SQL help
Hey I think I've got a pretty easy question. How do you select only the most recent date from a table with SQL?
Hope someone can respond soon. Thanks to all
Krash_io
Krash_io
www.recipebomb.com
www.computerbomb.com
Hey I think I've got a pretty easy question. How do you select only the most recent date from a table with SQL?
Hope someone can respond soon. Thanks to all
Krash_io
Krash_io
www.recipebomb.com
www.computerbomb.com
Mark Hensler posted this at 06:29 — 27th January 2002.
He has: 4,048 posts
Joined: Aug 2000
SELECT * FROM table_name ORDER BY field_name DESC LIMIT 1
Where field_name is your Timestamp/DateTime/Date data type field.
krash_io posted this at 07:07 — 27th January 2002.
They have: 49 posts
Joined: Dec 2001
That seems to give me an error on LIMIT.
Any suggestions?
Wil posted this at 15:31 — 27th January 2002.
They have: 601 posts
Joined: Nov 2001
Try this:
SELECT * FROM table_name ORDER BY field_name DESC LIMIT 0,1
Mark Hensler posted this at 22:36 — 27th January 2002.
He has: 4,048 posts
Joined: Aug 2000
What kind of server are you using? (mySQL, M$ SQL, MS Access, etc.) There are some differences among these servers... the LIMIT query being one of them.
mySQL is what Will & I posted.
mySQL Docs: 6.4.1 SELECT Syntax
M$ SQL would look like this:
SELECT TOP 1 * FROM table_name ORDER BY field_name
M$ SQL Docs: SELECT
Mark Hensler
If there is no answer on Google, then there is no question.
krash_io posted this at 03:26 — 28th January 2002.
They have: 49 posts
Joined: Dec 2001
Unfortunately I'm using Access
-Krash
Mark Hensler posted this at 04:01 — 28th January 2002.
He has: 4,048 posts
Joined: Aug 2000
It should work with the same query that MS SQL Server uses.
SELECT TOP 1 * FROM table_name ORDER BY field_name
krash_io posted this at 05:44 — 28th January 2002.
They have: 49 posts
Joined: Dec 2001
Hey that worked great, but I needed to add a DESC to the end of that to get the news date, thanks for your help!
Krash_io
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.