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.
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, VALUE0, 11, 22, 783, 91returning:ID, VALUE0, 13, 91Sorry for the newbie question... All help is appreciatedThanks! |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-02-25 : 17:17:39
|
SELECT * FROM TABLEWHERE (ID = (SELECT MIN(ID) FROM TABLE)OR ID = (SELECT MAX(ID) FROM TABLE)) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-26 : 02:14:19
|
OR1 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 MadhivananFailing to plan is Planning to fail |
|
|
|
|
|