Page 1 of 1
mysql Query
Posted: Wed Nov 12, 2008 12:41 pm
by leewad
Hi
I`m wanting to query my mysql database to list the latest records by that day, for example:
if today i update the database it will pull all todays listing but if not i want it to pull the last date range listing so if I did it last updated it friday it will pull these listings ( only these on this date not the ones before this), so basically I want to group the listing by the latest update.
Could anyone please help me with the query?
Re: mysql Query
Posted: Wed Nov 12, 2008 4:12 pm
by TeNDoLLA
Could you post some code how you are trying to do it now? It is quite hard to guess how you db structure is designed and how you are trying to pull the data out of it at the moment.
Re: mysql Query
Posted: Wed Nov 12, 2008 7:01 pm
by aceconcepts
Well in order to get the latest or earliest date you can use ORDER BY i.e.
Code: Select all
$query=mysql_query("SELECT * FROM table_name ORDER BY date_field");
To alternate the order use ASC or DESC respectively - ORDER BY defaults to ASC.
Re: mysql Query
Posted: Thu Nov 13, 2008 1:01 am
by leewad
Code: Select all
$query=mysql_query("SELECT * FROM table_name ORDER BY date_field");
This will list all records not all records on latest date.
If I have 10 records added on the 12-11-2008, 9 records added on the 08-11-2008 and 5 records added on the 06-11-2008 then I would like it to display the 10 records which were added on the 12-11-2008, if todays date was 10-11-2008 then it would only display the 9 records which were added on the 08-11-2008
Re: mysql Query
Posted: Thu Nov 13, 2008 3:34 am
by aaronhall
You can pass a DATETIME, TIMESTAMP or DATE column into the MAX() function and figure out the latest date for which there are rows in the table
Re: mysql Query
Posted: Thu Nov 13, 2008 8:13 am
by aceconcepts
Try and play around with it yourself - not being rude but you usually learn more when you research and test by trial and error

Re: mysql Query
Posted: Thu Nov 13, 2008 10:12 am
by pickle
Since this is a MySQL Database question, I've moved it to the Databases forum.