New answers tagged


Here is one way to avoid hitting table 2 twice: select tmp.* from ( select id, phone1 as phone_num, date from table_1 union all select id, phone2 as phone_num, date from table_1 ) tmp left join table_2 t2 on phone_num in (t2.phone1, t2.phone2) where is null


Why are you using a compound key for your PRIMARY key for the app table? That seems nonsensical. What you're telling the DB engine is that it's allowed to have multiple entries for a single instance_id in the app table, providing that either the app_id or the is_live value are different for each row. So you could have something like this: instance_id | ...


I don't see any indexes defined in the SQL. Adding indexes should improve the performance. The MySQL documentation for indexes

Top 50 recent answers are included