Re: 'OR' logic in mySQL query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Ron Piggott <ron.php@xxxxxxxxxxxxxxxxxx>:
> Am I able to use the OR logic in mySQL queries?
>
> $query = "SELECT * FROM table WHERE date_received LIKE '$todays_date' OR
> '$yesterdays_date' ORDER BY prayer_request_reference ASC";
>
> In this above example will the " OR '$yesterdays_date' " work?
>
> In reality I am wanting to preview new entries to the database within the
> past 2 days

First off, did you try it? You could have tried it and had a more
specific question in the time it took you to ask the above question.

Second: In SQL, as in PHP, an OR requires that you have the values
you're testing against on either side. To be specific,
'$yesterdays_date' is a true value, and it's not what you're testing;
you're wanting to see if date_received is like that value -- inother
words, date_received LIKE '$yesterdays_date' is what you're actually
trying to test. That said, you'll get much better results with:

SELECT *
FROM table
WHERE
    date_received LIKE '$todays_date' OR
    date_received LIKE '$yesterdays_date'
ORDER BY
    prayer_request_reference ASC

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:matthew@xxxxxxxxxx         | http://vermontbotanical.org

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux