on-internet
← Community

LEFT JOIN with WHERE in a first table's field OR second table's field

Stack Overflow ·

SELECT COALESCE(tb2.number_new, tb1.number_original) as number FROM tb1 LEFT JOIN tb2 ON tb2.id = tb1.id WHERE tb1.number_original = <PARAM> OR tb2.number_new = <PARAM> The above query generates a full table scan. How to optimize it? EXPLAIN: +----+-------------+-------+-------+----------------+----------------+---------+------+----------+----------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+----------------+----------------+---------+------+----------+------------------

Comments

Sign in or sign up to comment and upvote.

No comments yet.