Page 1 of 1

Two MySQL AND's returns blank query, one does not?

Posted: Mon Aug 25, 2008 9:43 pm
by JAB Creations
Works...

Code: Select all

if (!isset($_GET['folder'])) {$result1 = mysql_query("SELECT id, id_from, date_0, date_1, message, subject FROM `public_private_messages` WHERE id_for = '".$_SESSION['member']."' AND id_for_folder = 'New'");}
Returns blank query...

Code: Select all

if (!isset($_GET['folder'])) {$result1 = mysql_query("SELECT id, id_from, date_0, date_1, message, subject FROM `public_private_messages` WHERE id_for = '".$_SESSION['member']."' AND id_for_folder = 'New' AND id_for_folder = 'Read'");}
...can any one please explain to me why? 8O Does MySQL not allow multiple AND's?

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 12:02 am
by Bill H
id_for_folder = 'New' AND id_for_folder = 'Read'
MySQL allows as many AND's as you need but id_for_folder is going to equal one or the other, it can't equal both.

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 12:24 pm
by JAB Creations
Does MySQL support OR then?

If not how do I make a query for "New" and "Read" messages simultaneously?

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 12:30 pm
by jayshields
It supports OR.

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 12:31 pm
by JAB Creations
AH-HA! It does! :mrgreen:

I renamed a private message title (and obviously it's status) to include READ in the subject (and as "Read" in the status column) and it displayed along with all the "New" status messages.

Where can I find this in MySQL's documentation? I'm finding it confusing to navigate right now.

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 12:55 pm
by jayshields
I don't understand what you're after. It doesn't matter what is in the subject, as long as your other criteria are fulfilled and the status is either read or new, then it will be returned in the result set.

Re: Two MySQL AND's returns blank query, one does not?

Posted: Tue Aug 26, 2008 1:58 pm
by Bill H
Where can I find this in MySQL's documentation?
The documentation includes indexes and search boxes, and a search under SELECT gives a lot of information on how to use queries.