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?
mysql Query
Moderator: General Moderators
Re: mysql Query
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.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: mysql Query
Well in order to get the latest or earliest date you can use ORDER BY i.e.
To alternate the order use ASC or DESC respectively - ORDER BY defaults to ASC.
Code: Select all
$query=mysql_query("SELECT * FROM table_name ORDER BY date_field");Re: mysql Query
Code: Select all
$query=mysql_query("SELECT * FROM table_name ORDER BY date_field");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
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
Re: mysql Query
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
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: mysql Query
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
Since this is a MySQL Database question, I've moved it to the Databases forum.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.