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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post 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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post by JAB Creations »

Does MySQL support OR then?

If not how do I make a query for "New" and "Read" messages simultaneously?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

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

Post by jayshields »

It supports OR.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

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

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

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

Post 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.
Post Reply