鉴于这种表结构和示例数据(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