Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 基于依赖于表而非仅依赖于行的条件获取行_Mysql - Fatal编程技术网

Mysql 基于依赖于表而非仅依赖于行的条件获取行

Mysql 基于依赖于表而非仅依赖于行的条件获取行,mysql,Mysql,假设我有一个包含两列(索引)的表:文档ID和文档包含的单词 ____________________ __docID__|__Word___| 1 | it | 1 | rains | 2 | this | 2 | is | 2 | cold | 3 | it | 3 | is | 3 | snowing | 因此,表中有三个文

假设我有一个包含两列(索引)的表:文档ID和文档包含的单词

____________________
__docID__|__Word___|
    1    |    it   |
    1    |  rains  |
    2    |  this   |
    2    |    is   |
    2    |  cold   |
    3    |    it   |
    3    |    is   |
    3    | 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');

这可以在一次选择中完成吗?@草莓我们确实也可以使用联接实现同样的效果。考虑到文档可能包含不同的字数,您将如何使用联接来实现它。@FiboKowalsky可能是这样的<代码>选择main.*从main.docID=sub.docID和sub.Word='it'上的一些表main、一些表sub