Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get top x records

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-03-09 : 03:44:52
i know i can say
select top 5 customerid,customername from customers

but how can i query to return all but the first record

so if I have in customers

name date
esther 3-3
esther 3-4
esther 3-5
johm 3-5
esther 3-6
esther 3-4

I want to return all customers with name esther except the one with the highest date so my query should return

name date
esther 3-3
esther 3-4
esther 3-5
esther 3-4






jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-03-09 : 04:32:31
one way of doing it

select name, date
from customers
where name='esther'
and date<(select max(date) from customers where name='esther')

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -