| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
How to select a record based on 1 field being min/maxHi, say the table has these films records in table called BOXOFFICE
I want latest results picked out of this: Code:
FILM Updated Week Result ======================================================= Indiana Jones 5/30/2008 1 Hit Indiana Jones 6/7/2008 2 Hit Hancock 7/4/2008 1 Hit Hancock 7/11/2008 2 Average Titanic 12/25/1997 1 Hit Titanic 2/25/1998 10 Superhit Titanic 3/25/1998 14 Blockbuster Code:
Indiana Jones 6/7/2008 2 Hit Hancock 7/11/2008 2 Average Titanic 3/25/1998 14 Blockbuster SELECT film, max(updated), week, result FROM box officeI don't think is the correct query. What might work? Its a long problem I've had in sql. How to select an entire record, based on one of its fields being the min/max for that field among all the records. Thanks. |
|
|||
|
select film,updated,week,result from boxoffice where updated=(select max(updated) from boxoffice)
....................................... the subquery will return the maximum value of column named updated which form the where condition for the outer query ie..where updated=(maximum value of column named updated)[in this case latest date] hope this was helpful 4 u Last edited by arun : 07-22-2008 at 12:24 PM. |