Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

neer to select values which is in common Expand / Collapse
Author
Message
Posted Monday, March 24, 2014 6:13 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:51 PM
Points: 62, Visits: 91
i have a temp table #student_details
which contains below values
student_id subject_id
1 111
3 111
4 111
5 111
3 121
4 121

i need to select the students which is common in both subjects,what should i do???
i am new to sql, can anyone help??
Post #1554000
Posted Monday, March 24, 2014 6:21 AM This worked for the OP Answer marked as solution


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:15 AM
Points: 13,017, Visits: 10,800
SELECT student_id, cnt = COUNT(subject_id)
FROM #student_details
GROUP BY student_id
HAVING COUNT(subject_id) > 1;

Since this is most likely a homework assignment of some sorts, make sure you at least understand the solution given.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1554002
Posted Monday, March 24, 2014 6:32 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, September 19, 2014 11:51 PM
Points: 62, Visits: 91
thanks a lot..
Post #1554007
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse