首先查询:
SELECT `id`
FROM (`videos`)
WHERE `name` LIKE '%Dragon Ball Z (U.S.)%'
和第二
SELECT `vid_id` as id
FROM (`other_names`)
WHERE `name` LIKE '%Dragon Ball Z (U.S.)%'
GROUP BY `vid_id`
我想要的只是LIKE
的唯一ID列表。
答案 0 :(得分:2)
将'和'替换为'UNION'。 :)
SELECT `id`
FROM (`videos`)
WHERE `name` LIKE '%Dragon Ball Z (U.S.)%'
UNION
SELECT `vid_id` as id
FROM (`other_names`)
WHERE `name` LIKE '%Dragon Ball Z (U.S.)%'
UNION
(与UNION ALL
相对)已经仅返回唯一商品,因此您不需要GROUP BY
或SELECT DISTINCT
。如果你认为它更清楚,你可以写UNION DISTINCT
,但你可以省略它,因为它是UNION
的默认行为。