Is there an opposite but equivalent UNION function for mysql?
I know it’s possible to do this with a longer query but I’m curious on whether or not there’s a function equivalent.
I have 2 select statements for 2 different tables
select state, state_name, id, idname, phone, mobile, home from table1
select state, state_name, id, idname, phone, mobile, home from table2
And I need a query that pulls only from table1 and ONLY if idname, phone, mobile, home from table1 doesn’t match with table2
For example: Table1 has
AK | Alaska | 1 | row6 | 453 | 567 | 123
but Table 2 has:
AK | Alaska | 1 | row6 | 453 | 567 | 123
AK | Alaska | 1 | row6 | NULL | 567 | 123
AK | Alaska | 1 | tttttt | 453 | 567 | 123
The query will display
AK | Alaska | 1 | row6 | NULL | 567 | 123
AK | Alaska | 1 | tttttt | 453 | 567 | 123
will NOT display
AK | Alaska | 1 | row6 | 453 | 567 | 123
In standard SQL you can use the ANSI SQL
EXCEPToperator which is an exact analogue ofUNIONThere is also an
INTERSECTset operator that would show rows that both sources have in common.Unfortunately neither of these are supported in current versions of MySQL so you need to use one of these other 3 more verbose ways of achieving an anti semi join.
NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL