The MySQL does not support INTERSECT operator. However you can still achive using join, depending on the complexity of the INTERSECT query. Basically, the INTERSECT operator takes the results of two queries and returns only rows that appear in both result sets.
To fetch the results of two queries and returns only rows that appear in both result sets, use the following syntax:
Parameters:
tablename1 & 2: The table name from which you want to achive INTERSECT
operator.
JOIN
to perform INTERSECT operator in MySQL:
Note:
In the above example, the JOIN
is used to achive INTERSECT with MySQL.
You can use MySQL Command Line Client to achive INTERSECT
in MySQL using join. It will look like this: