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 |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-01-22 : 15:05:15
|
| Hi just having trouble with a group clausei want to select all from my table but group the selection by a single column which is SchGroupViewso if SchGroupView contains 10 rows with a value of 4478 then i only want to show the first record.any ideas how i can do this?SELECT SchGroupView, SchSMS_Date, SchSMS_Time, SchProcessID, SchMessageText, SchMessageTo, SchMessageFrom, SchMessageClickaID, SchWay, SchServerDateTimeFROM ScheduledGROUP BY SchGroupView |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-01-22 : 15:10:54
|
What would you want your output to be from the following dataset?SchGroupView SchSMS_Date SchSMS_Time4478 20080101 09:14:424478 20080102 13:29:014478 20080102 16:57:33 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-22 : 23:13:12
|
quote: Originally posted by craigmacca Hi just having trouble with a group clausei want to select all from my table but group the selection by a single column which is SchGroupViewso if SchGroupView contains 10 rows with a value of 4478 then i only want to show the first record.any ideas how i can do this?SELECT SchGroupView, SchSMS_Date, SchSMS_Time, SchProcessID, SchMessageText, SchMessageTo, SchMessageFrom, SchMessageClickaID, SchWay, SchServerDateTimeFROM ScheduledGROUP BY SchGroupView
SELECT SchGroupView, SchSMS_Date, SchSMS_Time, SchProcessID, SchMessageText, SchMessageTo, SchMessageFrom, SchMessageClickaID, SchWay, SchServerDateTimeFROM Scheduled sINNER JOIN (SELECT SchGroupView,MIN(SchSMS_Date) AS SchSMS_Date FROM Scheduled GROUP BY SchGroupView)tON t.SchGroupView=s.SchGroupViewAND t.SchSMS_Date =s.SchSMS_Date |
 |
|
|
|
|
|
|
|