Last records

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Last records

Post by leebo »

Is there a way of finding the last 10 records added to the database or records added in the last 14 days etc.. either way will do !


In ASP i would have used:

<%datenow = DateAdd("D", -14, date)
date3= FormatDateTime(datenow,vbshortdate)
date2= year(date3) &"/"& month(date3)&"/"&day(date3) %>

<%RS.Open "SELECT * FROM table1 WHERE date => '" & date2 & "' order by date", con, 3, 3 %>


Thanks
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

you didn't mention what DB

Post by lostboy »

so i will assume mysql

select * from table order by date desc limit 10

which will take the last 10 (limit 10) records order by date from latest to earliest (desc)

hth
laserlight
Forum Commoner
Posts: 28
Joined: Wed Jan 01, 2003 6:41 am

Post by laserlight »

hmm... but leebo wants the last 10 in the database, not just a table.

Maybe a join of all the tables in the database could be made, then such a query?
I havent quite experimented with joins yet.
leebo
Forum Commoner
Posts: 44
Joined: Sun Oct 20, 2002 9:49 am

Post by leebo »

Thanks guys i have now sorted it
Post Reply