鑑於這種表結構和示例數據(T3不應在查詢中使用,這是隻有在這裏顯示T1和T2之間的關係):有沒有辦法在這種類型的SQL SELECT中刪除嵌套查詢?
t1 t2 t3
-------------- ----------------- --------------------------------
| id | value | | t1key | t3key | | id | value |
| 1 | 2008 | | 3 | 1 | | 1 | "New intel cpu in 2010" |
| 2 | 2009 | | 4 | 1 | | 2 | "New amd cpu in 2008" |
| 3 | 2010 | | 6 | 1 | | | ... |
| 4 | intel | | 1 | 2 | --------------------------------
| 5 | amd | | 5 | 2 |
| 6 | cpu | | 6 | 2 |
| | ... | | | ... |
-------------- -----------------
你將如何構建一個SQL查詢,將滿足以下內容:
Given the input for t1.id is the set {6} returns t1.id set {3,4,6,1,5}
Given the input for t1.id is the set {6,4} returns t1.id set {3,4,6}
Given the input for t1.id is the set {5,4} returns t1.id set {}
並且在表更大時不會導致性能下降...?
我不明白的規格。 「指定t1.id是否是...」是什麼意思? – 2011-03-30 06:46:08
可以調用表t1'單詞',調用表t3'短語'和調用表t2'單詞是短語'。我想你想找到與特定的一組words.ids相同的詞組中的所有words.id。那是對的嗎? – 2011-03-30 06:56:19
@Stefan:「指定t1.id是集合{6}」的意思是「WHERE t1.id = 6」..隨着集合的增長,它變得棘手。 @ypercube:非常多,但所有重要的單詞都已從短語中刪除並放入t2 :) – 2011-03-30 07:38:16