View Full Version : sql query syntax problem
zodehala
05-12-2008, 04:57 PM
http://img241.imageshack.us/img241/6599/phpan7.jpg
why is following query result empty
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` =22 AND `parentid` =0;
abduraooft
05-12-2008, 05:22 PM
`parentid` =22 AND `parentid` =0; Are your trying to get the result of OR
A filed can't hold two different values in a single row.
zodehala
05-12-2008, 06:45 PM
Are your trying to get the result of OR
A filed can't hold two different values in a single row.
so
how can i select username which parentid are 0 and 22 ?
Fumigator
05-12-2008, 07:03 PM
Multiple personality disorder is a human condition which fortunately does not spread to databases. As has already been mentioned, it's impossible for a single column in a single row to contain more than one value. If the value is 0, then it can't be 22, and visa-versa. If the value is "0,22" then the value is neither 0 nor 22, it's "0,22".
_Aerospace_Eng_
05-12-2008, 08:16 PM
Use
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` =22 OR `parentid` =0;
which has already been stated. I suggest doing some mysql tutorials.
derzok
05-13-2008, 05:02 PM
Yes, you need to use an OR statement instead of an AND. What you're asking it to do is select all of the rows where the parentid is equal to both 0 AND 22 at the same time - which is impossible. No number can be 0 and 22 at the same time. You want to select the rows where the parentid is 0 or the parentid is 0.
One of the downfalls of an english based syntax :rolleyes:
technica
05-14-2008, 08:23 AM
Try this query, this will work:
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` in (22,0);
If this query gives syntax error then use this:
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` in ('22','0');
This query will fetch all the records whith threadid=22 and parentid qual to 22 and 0
Hope this helps
zodehala
05-14-2008, 07:15 PM
Try this query, this will work:
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` in (22,0);
If this query gives syntax error then use this:
SELECT `postid` , `threadid` , `parentid` , `username` , `title` , `pagetext`
FROM `post`
WHERE `threadid` =22 AND `parentid` in ('22','0');
This query will fetch all the records whith threadid=22 and parentid qual to 22 and 0
Hope this helps
thanx u r perfect
Fumigator
05-14-2008, 08:47 PM
To clarify the IN(x,x) syntax is an alternative to normal OR syntax, so you're still not testing if parentid = 0 and parentid = 22. But whatever. :)
zodehala
05-15-2008, 01:51 PM
To clarify the IN(x,x) syntax is an alternative to normal OR syntax, so you're still not testing if parentid = 0 and parentid = 22. But whatever. :)
but it is running:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.