Re: Using OR in a SELECT statement

From: Date: Tue, 28 Mar 2006 14:55:21 +0000
Subject: Re: Using OR in a SELECT statement
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-41623@lists.php.net to get a copy of this message
At 02:40 AM 3/28/2006, Arno Kuhl wrote:
Newbie MySQL question... I have a situation where if I don't have a custom value then I must use the default value. There will always be a default value but there may also be a custom value. I could do this with: select value where id and custom condition if (EOF) { select value where id and default condition if (EOF) {
    // no value found for this id - error, return false
} } // return value If I change this to: select value where id and (custom condition or default condition) ... will I always get the custom value if there is one, or do I have to have 2 selects to be sure that I always get the custom value if there is one? IE does MySQL consistently read and process the OR statement from left to right or does it change depending on what's most optimal? Cheers Arno
This is really a MySQL question, but check section 12 of the MySQL manual. Here's the link for operator precedence http://dev.mysql.com/doc/refman/4.1/en/operator-precedence.html I'd run some simple tests, just on the OR to see how it behaves. I usually have to make at least two passes on logical conditions to get them right. Where is your EOF() coming from? If you are cascading the statements, use mysql_num_rows() or just test for the value returned from mysql_query(). Hope this has been helpful - Miles -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.385 / Virus Database: 268.3.2/294 - Release Date: 3/27/2006

« previous php.db (#41623) next »