If you have the option to change the table structure, just replace
the date and time columns with a timestamp column.
If you must keep the current structure then the following wil
work, but it will not use indexes in the search:
select ...
where concat(today,' ',heure1)
between '2002-01-01 17:00:00' and '2002-01-30 08:00:59';
To allow MySQL to use an index on today, add an extra clause:
select ...
where today between '2002-01-01' and '2002-01-30'
and concat(today,' ',heure1)
between '2002-01-01 17:00:00' and '2002-01-30 08:00:59';
The following would also work, and might allow an index scan of an
index on (today, heure1):
select ...
where today between '2002-01-01' and '2002-01-30'
and (today > '2002-01-01' or heure1 >= '17:00:00')
and (today < '2002-01-30' or heure1 <= '08:00:59');
> From: "Inandjo Taurel" <[EMAIL PROTECTED]>
> Subject: How to write this query??
> Date: Thu, 23 Jan 2003 18:36:40 +0000
> hi all,
> i have a table trans with this structure:
> today(date) | heure1(time) | amount(double) | client(varchar 30)
> Now i need to write a query that would take the start date and time, end
> date and time, and return all the records between the two.
> So for example, the query should return all records between 01/01/2002 at
> 17:00 and 01/30/2002 at 08:00.
> How can i get that query in one query??
> SQL SQL
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php