B
B
Big_person2015-11-23 11:57:14
MySQL
Big_person, 2015-11-23 11:57:14

How to select data from SQL table for the last day, by datetime field?

There is a table in which there is a created column with the datetime format: 2015-11-20 15:22:47
You need to get all rows from the table, according to the created field for the last day, the nearest one (it can be either today or a few days ago), which is in the table.
SELECT * FROM table WHERE created=?
Is it possible to do with one request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-11-23
@Big_person

SELECT `t`.* 
    FROM (
        SELECT DATE(MAX(`created`)) AS `date`
            FROM `table`
    ) AS `d`
    JOIN `table` AS `t` ON `t`.`created` >= `d`.`date`

N
nozzy, 2015-11-23
@nozzy

select 
t.id, t.date
from table1 t
where t.date >= ( select max(date) from table1 where id = t.id )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question