我有一個這樣的表,類型是innodb,id和sid是索引的。在查詢中使用'as'
id | sid
##########
1 | 100
1 | 101
1 | 102
1 | 103
1 | 104
1 | 105
2 | 100
2 | 101
3 | 100
3 | 101
我需要id's sid 100,... 105 like id = 1。 我有這個疑問
select t1.id
from test as t1, test as t2, test as t3,
test as t4, test as t5, test as t6
where t1.sid=100
and t2.sid=101
and t3.sid=102
and t4.sid=103
and t5.sid=104
and t6.sid=105
and t1.id = t2.id = t3.id = t4.id = t5.id = t6.id
但是當我運行查詢的phpmyadmin掛起。 記錄數是2000.
什麼是優化查詢?
我有點困惑。你想用這個查詢做什麼? –
顯然,他希望挑出ID與{100 .. 105}中每個sid值相關聯的所有ID值。如果其中一個sid值丟失,請忽略該ID。 –