I have two tables with the same column name. I want to search in them.I've research and realized that using UNION ALL
is better that INNER JOIN
(in terms of speed and performance). Now i want to know if the result is not found, UNION ALL
is better yet ?
I think the algorithm of JOIN Keyword is: if the result is not found in the first table, operation stops (in the second table, the search will not be). But UNION ALL
search all the tables in any case.my thought is right ? If my thought is right then INNER JOIN
is better when the result is not found ?
point: col is indexed (phpmyadmin).
Now which one have better performance if the result is not found ?
SELECT col FROM table1 WHERE col='test'
UNION ALL
SELECT col FROM table2 WHERE col='test';
VS
SELECT col
FROM table1
INNER JOIN table2
ON table1.col=table2.col
WHERE col='test';