我有一個名爲Index
表具有列id
和value
,其中id
是一個自動遞增BIGINT和value
是一個英文單詞爲varchar。SQL指數基於搜索
我有一個名爲Search
的表,它與表Index
有關係。對於每個搜索,您可以定義它應該在名爲Article
的表中搜索哪些索引。
表Article
也與表Index
有關係。
限定的關係的表格是:
Searches_Indexes
與列id_search
和id_index
。
Articles_Indexes
帶有列id_article
和id_index
。
我想找到所有包含相同搜索索引的文章。
例如:我有一個Search
使用索引laptop
和dell
,我想檢索所有Article
S的同時包含索引,不只是一個。
到目前爲止,我有這樣的:
SELECT ai.id_article
FROM articles_indexes AS ai
INNER JOIN searches_indexes AS si
ON si.id_index = ai.id_index
WHERE si.id_search = 1
如何讓我的SQL只全部Search
的Index
ES返回Article
S'
編輯:
樣本數據:
文章:
id | name | description | ...
1 | 'Dell Laptop' | 'New Dell Laptop...' | ...
2 | 'HP Laptop' | 'Unused HP Laptop...' | ...
...
搜索:
id | name | id_user | ...
1 | 'Dell Laptop Search' | 5 | ...
指數:
id | value
1 | 'dell'
2 | 'laptop'
3 | 'hp'
4 | 'new'
5 | 'unused'
...
Articles_Indexes:
Article
與id
1(戴爾筆記本電腦)具有Index
ES '戴爾', '膝上型', '新'。
Article
與id
2(惠普筆記本電腦)有Index
es'筆記本電腦','hp','未使用'。
id_article | id_index
1 | 1
1 | 2
1 | 4
...
2 | 2
2 | 3
2 | 5
...
Searches_Indexes:
Search
與id
1只包含2個Index
ES, '戴爾' 和 '膝上型':
id_search | id_index
1 | 1
1 | 2
需要的輸出:
id_article
1
表稱爲搜索和索引...你有哪些表 - 列,在哪裏,選擇和值? – jarlh
已更新,使其更清晰一點。我有兩個關係表'Searches_Indexes'和'Articles_Indexes',它們基本上定義哪些搜索具有哪些索引,哪些文章具有哪些索引。 –
[編輯]你的問題,並根據這些數據添加一些樣本數據和預期的輸出。 [_Formatted_](http://dba.stackexchange.com/help/formatting)**文本**請[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i -not-upload-images-code-on-so-when-asking-question-285557#285557) –