Page 1 of 1
selecting newest record
Posted: Sun Nov 10, 2002 11:27 am
by DynamiteHost
Hey,
I want to select a field called "date" from a table where "client"=$client
but I need to select the field with the newest id number from those matches....
Any ideas anyone?
Thanks

Posted: Sun Nov 10, 2002 11:46 am
by volka
http://www.mysql.com/doc/en/SELECT.html6.4.1 SELECT Syntax
SELECT [STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS] [HIGH_PRIORITY]
[DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO {OUTFILE | DUMPFILE} 'file_name' export_options]
[FROM table_references
[WHERE where_definition]
[GROUP BY {unsigned_integer | col_name | formula} [ASC | DESC], ...
[HAVING where_definition]
[ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...]
[LIMIT [offset,] rows]
[PROCEDURE procedure_name(argument_list)]
[FOR UPDATE | LOCK IN SHARE MODE]]
Posted: Sun Nov 10, 2002 11:48 am
by DynamiteHost
i've already looked at that and i cant understand any of it...
Posted: Sun Nov 10, 2002 11:53 am
by volka
Code: Select all
SELECT ... WHERE client= ... ORDER BY date DESC LIMIT 1
will select only the recordset with the greatest value (what ever this is) in
date
Posted: Sun Nov 10, 2002 12:54 pm
by DynamiteHost
that works a treat, thankies
