LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-06-2008, 07:05 AM   #1
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 37
Exclamation Help on explanation of MySQL SELECT query


Hello,

Can anyone tell me why this works like this in mysql !!
How come an Integer value gets selected using (--) with it?

PHP Code:

mysql
desc test;                        
+-------+---------+------+-----+---------+----------------+
Field Type    Null Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
a     int(11) | NO   PRI NULL    auto_increment |
+-------+---------+------+-----+---------+----------------+
1 row in set (0.01 sec)

mysqlselect from test;
+-------+
a     |
+-------+
|     
|
|     
|
|   
133 |
76255 |
+-------+
4 rows in set (0.00 sec)

mysqlselect from test where a ;
+---+
|
+---+
|
+---+
1 row in set (0.00 sec)

mysqlselect from test where a --;
+---+
|
+---+
|
+---+
1 row in set (0.00 sec)
// This query asks for another semicolon(;) but displays the result too  !! 
mysqlselect from test where a 1-- ;
    -> ;
+---+
|
+---+
|
+---+
1 row in set (0.00 sec
 
Old 08-06-2008, 07:23 AM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 995

Rep: Reputation: 130Reputation: 130
"--" means that what follows is a comment. It doesn't need any separator inbetween.
e.g.

...where myvarcharfield = 'ciao'--blablablah

"--blablablah" is a comment
 
Old 08-06-2008, 07:59 AM   #3
carlmarshall
Member
 
Registered: Jan 2004
Location: North Yorkshire, UK
Distribution: Centos 5
Posts: 133

Rep: Reputation: 16
From the MySQL Ref manual:

Comment Syntax:

From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on).

Carl.
 
Old 08-06-2008, 10:49 PM   #4
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Original Poster
Rep: Reputation: 37
Hi, thanks for reply.
I got the flaw now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
interesting MySQL query/view query :s mjh Programming 3 03-25-2008 07:30 AM
Perl script/mysql select query from a file mcdrr Programming 12 06-05-2007 12:00 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM
select query thru php outputs no result suchi_sood Programming 1 04-11-2006 10:21 AM
Bizarre SQL select query acid_kewpie Programming 6 01-20-2004 12:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration