这样要求的SQL语句该怎么写?

duhorse 2000-09-24 09:42:00
两个表格,都有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.
...全文
156 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
skydb 2000-10-02
  • 打赏
  • 举报
回复
以上答案全部错误:
select email.email,email.name from email
union all
select emailhand.email,emailhand.name from emailhand
order by 1

关键两点:(union all) and (order by 1)



duhorse 2000-09-25
  • 打赏
  • 举报
回复
不好意思,是我太粗心了,其实我的意思就是要
select email.email,email.name from email
union
select emailhand.email,emailhand.name from emailhand
yangzi 2000-09-25
  • 打赏
  • 举报
回复
我仔细看了题目的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
yangzi 2000-09-25
  • 打赏
  • 举报
回复
这样写试试:
select a.name as name ,a.email as email from email a
union
select a.name as naem ,a.email as email from emailhand a
土豆 2000-09-24
  • 打赏
  • 举报
回复
用select A.name,A.email,B.name,B.email from email A,emailhand B
不行吗?还有,这样查出来有什么意义呢,总应该有个判断条件吧。

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧