I have two tables:
Table A:
a_id, a_href, a_name,......
Table B:
b_id, b_href, b_name......
Both tables have indexes on their href column. I intend to union these tables and join them on another, something like
Select c_id, u.name FROM TableC
Left join (Select a_href AS href, a_name AS name FROM TableA
UNION
SELECT b_href AS href, b_name AS name FROM TableB) AS u ON u.href = c_href
I want to preserve the index on href columns in the union, so my join is fast. Do I have to dynamically create an index for that union, or is there a better way to do this?
UNION [DISTINCT]
orUNION ALL
. That is to say, is there a chance thattablea(a_href,a_name)
, is duplicated astableb(b_href,b_name)
DISTINCT