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 |
sqldba20
Posting Yak Master
183 Posts |
Posted - 2011-10-25 : 11:55:04
|
Folks,I need help on a SQL Query. I have a data in this format. I want to select only records where HID <= 2 TID Name HID Hname37 JAN 103 TOM38 NOV 103 TOM48 DEC 103 TOM58 MAR 103 TOM23 JAN 104 XYZ24 FEB 105 RUD26 MAY 109 PQR29 JUN 109 KHG12 JUL 109 KJG12 AUG 101 ABC7 SEP 116 UHKThe output should be: TID Name HID Hname23 JAN 104 XYZ24 FEB 105 RUD12 AUG 101 ABC7 SEP 116 UHKThanks ! |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-25 : 12:02:21
|
[code]select *from a_data d inner join ( select HID from a_data group by HID having count(*) <= 2 ) h on d.HID = h.HID[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-25 : 12:03:05
|
that doesn't make any sense.WHERE HID less than or equal to 2wouldn't remove any of those rows.HID are all Greater than 100Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
sqldba20
Posting Yak Master
183 Posts |
Posted - 2011-10-25 : 12:12:17
|
I should have said --- HID count......quote: Originally posted by Transact Charlie that doesn't make any sense.WHERE HID less than or equal to 2wouldn't remove any of those rows.HID are all Greater than 100Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
|
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-25 : 12:16:06
|
ah -- what khtan said then.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|
|