I would like to write an SQL statement that ...

I would like to write an SQL statement that returns a list that will return the record which's creation time is the latest out of a few that answer the same criteria.

How do I do that?

Liked this question? Tell your friends about it

3 Answers

Order by
Oldest to Newest
Newest to Oldest
Votes

I don't exactly understand your question, so it's either:

select max(creationTime) from whatever where criteria = 1

or:

select * from whatever where criteria = 1 order by creationTime desc

The 1st one. How do I ask a record what's its creation time?

you have to add the creation date as a column to the table...

 

and then you can run:

select top 1 * from tableName where (criteria=1) order by dateCreated desc 

Related Questions

Other people asked questions on similar topics, check out the answers they received:

Asked: What is DDL and DMl?

What is DDL and DMl?

Asked: SQL

Can I use " $sql="select * from books where id='$idprod' limit 1"; or $sql3="select * from magazines where id='$idprod' limit 1"; " in order to use the same php file for both situations?

Asked: How to use >all key word in sql queries

how to use >all key word in sql queries