I need to implement the following query in MySQL.
(select * from emovis_reporting where (id=3 and cut_name= \'全プロセス\' and cut_name=\'恐慌\') )
intersect
( sel
AFAIR, MySQL implements INTERSECT through INNER JOIN.
Your query would always return an empty recordset since cut_name= '全プロセス' and cut_name='恐慌'
will never evaluate to true
.
In general, INTERSECT
in MySQL
should be emulated like this:
SELECT *
FROM mytable m
WHERE EXISTS
(
SELECT NULL
FROM othertable o
WHERE (o.col1 = m.col1 OR (m.col1 IS NULL AND o.col1 IS NULL))
AND (o.col2 = m.col2 OR (m.col2 IS NULL AND o.col2 IS NULL))
AND (o.col3 = m.col3 OR (m.col3 IS NULL AND o.col3 IS NULL))
)
If both your tables have columns marked as NOT NULL
, you can omit the IS NULL
parts and rewrite the query with a slightly more efficient IN
:
SELECT *
FROM mytable m
WHERE (col1, col2, col3) IN
(
SELECT col1, col2, col3
FROM othertable o
)