e.hadid e.hadid - 22 days ago 8
MySQL Question

how to get Intersection of two query in mysql

I have a table that has two column with two foreign key from two different table.

this is my relation table:

table

I want to select those student who can speak both language with id 3 and 4.

How can i wrote a query to give me for e.x 12 , 14

Answer

Assume you relation is named "myRelation":

SELECT r1.student_Id FROM myRelation r1 join myRelation r2 on r1.student_id = r2.student_id where r1.language_Id = '3' and r2.language_id = '4'

Comments