My tables: big_table
+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | id | mediumint(7) | NO | PRI | NULL | auto_increment | | title | varchar(255) | NO | | NULL | | | category_id | tinyint(2) | NO | | NULL | | | sub_category_id | tinyint(2) | NO | | NULL | | | width | smallint(5) | NO | | NULL | | | height | smallint(5) | NO | | NULL | | | ratio_width | smallint(5) | NO | | NULL | | | ratio_height | smallint(5) | NO | | NULL | | | size | int(8) | NO | | NULL | | | mime | tinyint(2) | NO | | NULL | | | views | mediumint(7) | NO | MUL | NULL | | | time | int(10) | NO | | NULL | | | file | varchar(255) | NO | | NULL | | +-----------------+--------------+------+-----+---------+----------------+
small_table
+--------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+-------+ | id | mediumint(7) | NO | PRI | NULL | | | width | smallint(5) | NO | MUL | NULL | | | height | smallint(5) | NO | MUL | NULL | | +--------+--------------+------+-----+---------+-------+
so what's faster (example):
SELECT * FROM `big_table` WHERE `width` =1920 AND `height`=1080;
or use join
select big_table.*
from small_table
left join small_table small_table2
ON (small_table.id=small_table2.id
and `small_table`.`height` = '1080')
left join big_table
ON (big_table.id=small_table.id)
where small_table.width = '1920';
or join's from the same table?
select big_table.*
from big_table as big_table1
left join big_table big_table2
ON (big_table1.id=big_table2.id and `big_table1`.`height` = '1080')
left join big_table
ON (big_table.id=big_table1.id)
where big_table1.width = '1920';
or there is some better solution, better select's? (on both tables I can use indexes (width and height), but only ID is unique)