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 2000 Forums
 SQL Server Development (2000)
 Returning 2 rows, the MIN and MAX

Author  Topic 

flamz
Starting Member

21 Posts

Posted - 2008-02-25 : 17:11:41
Hello,
Is it possible to return 2 rows from a SELECT statement and these 2 rows would be chosen from the MIN AND from the MAX of a certain field?

ie:

ID, VALUE
0, 1
1, 2
2, 78
3, 91

returning:
ID, VALUE
0, 1
3, 91

Sorry for the newbie question... All help is appreciated
Thanks!



jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-02-25 : 17:17:39
SELECT * FROM TABLE
WHERE (ID = (SELECT MIN(ID) FROM TABLE)
OR ID = (SELECT MAX(ID) FROM TABLE))
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-26 : 02:14:19
OR

1

SELECT * FROM TABLE
WHERE ID IN (SELECT MIN(ID) FROM TABLE UNION ALL SELECT MAX(ID) FROM TABLE)

2 SELECT MIN(ID),MIN(VALUE) FROM TABLE UNION ALL SELECT MAX(ID),MAX(VALUE) FROM TABLE


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -