两个表格,都有NAME,EMAIL字段,要求一个查询可以联合所有两个表格的NAME和EMAIL字段。
我写的查询为什么不正确:
select email.name,email.email from email order by email.name
UNION
select emailhand.name,email.email from emailhand;
其中表名为EMAIL,EMAILHAND,数据库为ACCESS2000.
...全文
1565打赏收藏
这样要求的SQL语句该怎么写?
两个表格,都有NAME,EMAIL字段,要求一个查询可以联合所有两个表格的NAME和EMAIL字段。 我写的查询为什么不正确: select email.name,email.email from email order by email.name UNION select emailhand.name,email.email from emailhand; 其中表名为EMAIL,EMAILHAND,数据库为ACCESS2000.
我仔细看了题目的SQL,它有明显的错误
在后半句。
你要从emailhand表中取email表中的字段。当然不正确。
你可以写成
select Email.name as nameA,email.email as email,emailhand.name as nameB from
email,emailhand from email,emailhand where emailhand.email=email.email