0

我正在使用以下 SQL,并且想知道如何以及在何处放置 where 子句。这样我就可以将所有结果带入 id=2 的地方?

SELECT * 
FROM public_tips 
LEFT OUTER JOIN likes
USING (id) 
UNION 
SELECT * 
FROM likes 
RIGHT OUTER JOIN public_tips
USING (id)

我努力了

SELECT * 
FROM public_tips WHERE id=2
LEFT OUTER JOIN likes
USING (id) 
UNION 
SELECT * 
FROM likes WHERE id=2
RIGHT OUTER JOIN public_tips
USING (id)

但我得到一个语法错误!

4

1 回答 1

0

where子句在子句之后,子句fromjoin子句的一部分from

SELECT * 
FROM public_tips
LEFT OUTER JOIN likes
USING (id) 
WHERE public_tips.id=2
UNION 
SELECT * 
FROM likes 
RIGHT OUTER JOIN public_tips
USING (id)
WHERE public_tips.id=2
于 2013-09-01T20:03:13.900 回答