SQL record selection with dates until today

I have mysql DB with tables, of which in one table I have a date type field, I want the most recent past date - so I want it to order by date, in descending order, but record only records until today, and then use only the top with the LIMIT function, and also add a WHERE clause in what the clause should be for the selected city.

$result = mysql_query(" SELECT * FROM offers WHERE city = ".$_SESSION["city"]." ORDER BY exp_date DESC LIMIT 0, 1"); 
+6
source share
3 answers

ADD another condition where expression where

 $result = mysql_query(" SELECT * FROM offers WHERE city = ".$_SESSION["city"]." and Date < CURRENT_DATE() ORDER BY exp_date DESC LIMIT 1"); 
+11
source
 SELECT * FROM deals WHERE city = 2 AND exp_date < CURDATE() ORDER BY exp_date DESC LIMIT 0, 1 
+8
source

Add the following condition to:

... and exp_date < CURDATE()

See http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html .

+3
source

Source: https://habr.com/ru/post/908877/


All Articles