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
 General SQL Server Forums
 New to SQL Server Programming
 How to get the minimum /maximum from multiple rows

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2010-05-18 : 17:10:06
Hi,

I have a table containing records like:

file plot serial_start serial_end
---- ---- ------------ ----------
ABC 12 100001 100100
ABC 13 100101 100200
ABC 14 100201 100300
XYZ 79 100301 100500

I need to use a query that will fetch one row with the file name, minimum of serial_start and maximum of serial_end like....

file serial_start serial_end
---- ------------ ----------
ABC 100001 100300

How can I do that?
Thanks,

Nikhil1home
Starting Member

23 Posts

Posted - 2010-05-18 : 17:34:14
SQL 101 - first chapter :)

SELECT FILE, MIN(serial_start) AS Serial_start, MAX(serial_end) as serial_end
FROM YourTable
GROUP BY FILE
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2010-05-18 : 17:47:22
Oh, I tried that and had some errors or wrong data - so I got confused and was trying other things. I think I was trying wrong fields in the GROUP BY.
Thanks.
Go to Top of Page
   

- Advertisement -