検索したい以下のテーブルがあります。
Table A
+----+----------------------------+
| ID | description |
+----+----------------------------+
| 0 | horse going bad |
| 1 | Older Years of Resolutions |
| 2 | The knockknock pirate |
| 3 | The Wish list |
| 4 | list that's no list |
+----+----------------------------+
table TAGS
+----+------------+
| ID | tag |
+----+------------+
| 0 | list |
| 1 | knockknock |
+----+------------+
table TAGLINKS
+-------+--------+
| TAGID | JOKEID |
+-------+--------+
| 0 | 2 |
| 0 | 3 |
+-------+--------+
この検索を行うと:
select A.* from tags
join taglinks on tagid=tags.id
join A on A.id=jokeid
where tag in ('list','knockknock')
タグに「list」または「knockknock」のいずれか (または両方) を持つ A のすべてのエントリが表示されます (2,3)。私が探しているのは、両方のリストとノックノック タグ (2 のみ) に接続されているテーブル A からエントリを取得するクエリです。
また、テーブル A の説明を直接検索してこのデータを結合しています。これは考慮すべきことです。
今私は持っています:
select A.* from tags
join taglinks on tagid=tags.id
join A on A.id=jokeid
where tag in ('list','knockknock')
UNION
select * from A where locate('list',description) and locate('knockknock',description)
しかし、テーブルAからも3つ取得します。2つだけが必要です