Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a way to improve this query?

Status
Not open for further replies.

pandatime

Programmer
Joined
Jan 29, 2010
Messages
92
Location
AU
I can't do a group by because it returns *all* the rows grouped by file_dt. I just want the row with the max(file_dt).

Thanks

Code:
select convert(varchar,file_dt, 110) + ', ' + convert(varchar, tran_count) 
from myTable
where id = 1 
and file_dt = (select max(file_dt) from myTable where id = 1 and file_type = 'X') 
and file_type = 'X'
 
Good article, thanks, but I didn't see anything relating to my particular query.
 
Here is the explanation of the max function.
use tableschema;
go
select max(columnname) from tableschema.tablename;
go
 
Nevermind. What I was thinking of was TOP 1 with ORDER BY DESC. That would eliminate the need for the subquery to find the max date.
 
order by desc
or
order by asc
would do it. You are right! If you know how to use it.
 
Do you need to know the file size? Or do you need to know the max value of the values in a column?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top