Is there a better way to write this SQL query?

I want to return the row with the highest create_dt value. This works great, however, I would like to know if there is a better way to do this?

select * from 
table1 
where job_no='101047' 
and 
create_dt in
     (select max(create_dt) from    
      table1 where job_no='101047')
+3
source share
2 answers

What about:

Select top 1 *
from table1
where job_no = '101047'
order by create_dt desc
+15
source

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

It will work better

 Select top 1 * from table1 
 where job_no='101047'   
 order by create_dt desc
+4
source

Source: https://habr.com/ru/post/1714068/


All Articles