猿问

错误信息:Every derived table must have its own alias?

有A、B、C三个表,我想实现:先把A和B取合集,再将这个合集与C表取交集,也就是实现A∪B∩C,该怎么用SQL语句写呢?
首先感谢liaoxw624的回答,我试了一下
select x1.* from
(
(SELECT id FROM A)
UNION
(SELECT id FROM B)
)x1
INNER JOIN
C AS t1 ON t1.id=x1.id

提示错误信息:Every derived table must have its own alias

于是,我又试了一下这个:
select x2.* from
(
(
(SELECT id FROM A)
UNION
(SELECT id FROM B)
)x1
INNER JOIN
C AS t1 ON t1.id=x1.id
)x2

又提示说最后两行有语法错误,该怎么办呢?

幕布斯7119047
浏览 143回答 1
1回答

UYOU

题目太笼统,假设如下1。3个表列结构一样(不一样也可以,但必须保证可以取到相同的列射影)2。三个表都有相同的关键字,假设为ID则SQL文如下select t.* from--A∪B==>t(select * from Aunionselect * from B)t--A∪B∩Cinner join Con t.ID=C.ID
随时随地看视频慕课网APP
我要回答