Re: Help with SQL statement
| From: | David Otton | Date: | Mon, 03 Mar 2003 20:10:08 +0000 |
| Subject: | Re: Help with SQL statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137960@lists.php.net to get a copy of this message | ||
On Mon, 03 Mar 2003 12:04:37 -0800, you wrote:
>I have a database that holds a start date and an end date and I have a form
>with a start date and an end date. The report would be to get everything in
>the database's date ranges that overlap the form's date range. I am having
>trouble figuring out how to get this to work, any help is appreciated.
[if I understand you correctly]
you have 4 variables
db_start
db_end
form_start
form_end
and you want to select all rows where the range (db_start to db_end)
overlaps in any way with (form_start to form_end)?
You need two conditions, joined with an OR
(form_start => db_start AND form_start <= db_end)
OR
(form_end => db_start AND form_end <= db_end)
(BTW, this is an SQL question, not a PHP one.)