question

jeeshan.khan avatar image
jeeshan.khan asked

Retrive the data from Table having not more than 3 emp and with same deptno in sql server

first should like this id name emailid 1 amit amit@k.com 1 rachit rachit@k.com 1 vijay vijay@k.com 1 shalu shalu@k.com 2 bhalu bhalu@k.com 2 rana rana@k.com 2 kana kana@k.com 2 dena dena@k.com 2 shakila shalkila@k.com 2 vishakha visha@k.com 3 ramya ramya@k.com Result should be this id name emailid 1 amit amit@k.com 1 rachit rachit@k.com 1 vijay vijay@k.com 1 shalu shalu@k.com 3 ramya ramya@k.com
sqlsql server
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
where is deptno in that data?
3 Likes 3 ·

1 Answer

·
Squirrel avatar image
Squirrel answered
SELECT * FROM (SELECT ID FROM table GROUP BY ID HAVING COUNT(*) <= 3) m INNER JOIN table t ON m.ID = t.ID
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
Wow that's a leap of faith. It might answer the question in the title, but it certainly doesn't give the answer above!
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.