Is the performance of both these examples the same?
Example 1:
SELECT t1.wanted_1, t2.wanted_2
FROM table1 t1
INNER JOIN table2 t2 ON t1.common_col = t2.common_col
Example 2:
SELECT wanted_1, wanted_2
FROM
(SELECT wanted_1, common_col FROM table1)
INNER JOIN
(SELECT wanted_2, common_col FROM table_2) USING(common_col)
I am using example #2 at the moment since I am joining 15+ tables, each table with many unnecessary columns and many rows (1 million+)
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `table2` ADD INDEX `table2_idx_common_col` (`common_col`);
SELECT
t1.wanted_1,
t2.wanted_2
FROM
table1 t1
INNER JOIN
table2 t2
ON t1.common_col = t2.common_col