views:

158

answers:

2

I'm looking to return the row with biggest create_dt. This works fine, however I would like to know if there is a more proper way of doing this?

select * from 
table1 
where job_no='101047' 
and 
create_dt in
     (select max(create_dt) from    
      table1 where job_no='101047')
+15  A: 

How about:

Select top 1 *
from table1
where job_no = '101047'
order by create_dt desc
Dusty
Select top 1 * from table 1 where job_no = '101047' order by create_dt desc
msvcyc
thanks. Looks like I corrected before you had a chance to correct me. :)
Dusty
+1 I like this, I can get the min date by using asc. Thanks sir. There's just something about nested queries I don't like.
Jreeter
+4  A: 

your query will return more than one value if there is more than one row of create_dt
where job_no = '101047'

This will work better

 Select top 1 * from table1 
 where job_no='101047'   
 order by create_dt desc
John Nolan