假设我有一个包含两个(索引)列的表:文档 ID 和文档包含的单词。
____________________
__docID__|__Word___|
1 | it |
1 | rains |
2 | this |
2 | is |
2 | cold |
3 | it |
3 | is |
3 | snowing |
因此,表中表示了三个文档: it rains
、this is cold
、it is snowing
我如何有效地获取包含包含某个单词的文档的所有行的表格,假设Word = 'it'
:
____________________
__docID__|__Word___|
1 | it |
1 | rains |
3 | it |
3 | is |
3 | snowing |
查询可以如下所示:
SELECT * FROM table
WHERE (docID = this.docID, Word = 'it') is in table
你可以
使用它。
select
*
from
`some_table`
where `docID` in (select `docID` from `some_table` where `Word` = 'it');