cms9651
January 24, 2013, 10:35am
1
hi there, hope in your help.
I need to extract from my table:
all the rows of the previous day;
all the rows of the current day until 6 o’clock in the morning;
I tried this query but the output is null, I have two rows with previous day.
Can you help me?
thank you.
SELECT
*
FROM
mytable
WHERE
myDate BETWEEN DATE_SUB(
CURRENT_DATE (),
INTERVAL 1 DAY
)
AND (
CURRENT_DATE ()
AND myHour < '06:00'
);
Try
SELECT
*
FROM mytable
WHERE myDate = DATE_SUB(CURRENT_DATE (), INTERVAL 1 DAY)
OR ( myDate = CURRENT_DATE ()
AND myHour < '06:00'
)
r937
January 24, 2013, 12:48pm
4
it needs to be said that having two separate columns for date and time is usually a lot worse (for the resulting complexity in sql) than a single datetime column
cms9651
January 25, 2013, 10:58am
5
many thanks for suggestion!