我做了这个:

(SELECT numerocert FROM certificati)
UNION
(SELECT numeroarbo AS numerocert FROM cert_arbo)
UNION
(SELECT numeroerba AS numerocert FROM cert_erba)
WHERE numerocert = 12

我想看看这三张表中有没有12号,但不明白怎么回事。

最佳答案

where语句必须连接到调用3个表:

SELECT numerocert FROM certificati WHERE numerocert = 12
UNION
SELECT numeroarbo AS numerocert FROM cert_arbo WHERE numeroarbo = 12
UNION
SELECT numeroerba AS numerocert FROM cert_erba WHERE numeroerba = 12

或者你她使用外部查询:
select numerocert from (
  (SELECT numerocert FROM certificati)
  UNION
  (SELECT numeroarbo AS numerocert FROM cert_arbo)
  UNION
  (SELECT numeroerba AS numerocert FROM cert_erba)
)
WHERE numerocert = 12

10-08 00:36