neer to select values which is in common

  • 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??

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • thanks a lot..

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply