Sample Header Ad - 728x90

Presto/Mysql join validation

1 vote
3 answers
158 views
I have 2 tables, and the CASE statement below should only evaluate to 1/true if the record with the same lead_id exists in both tables. Here I have 2 ways of achieving this but just want to verify if its in fact the most optimal way of achieving this and which one is the better option here? The lead_id in t1 is the primary key and will always exist. I need to verify if its moved into the 2nd table **Query 1** SELECT CASE WHEN t1.lead_id = t2.lead_id THEN 1 ELSE 0 END AS valid FROM table1 t1 LEFT JOIN table2 t2 ON t1.lead_id = t2.lead_id **Query 2** SELECT CASE WHEN t2.lead_id IS NOT NULL AND t2.lead_id != 0 THEN 1 ELSE 0 END AS valid FROM table1 t1 LEFT JOIN table2 t2 ON t1.lead_id = t2.lead_id
Asked by code-is-life (117 rep)
Apr 28, 2022, 01:13 PM
Last activity: Apr 28, 2022, 06:09 PM