问2个SQL语句

rocket204 2007-11-29 09:07:10
1.建立一个一模一样的数据表,就数据表名不一样?
2.如何合并查询,如何查不符合条件的记录....例如:
select a.*,b.bj,b.i_date from book1 a left outer join book2 b on a.book_num=b.book_num
上面这句是查询,是左连接查询a表和b表中book_num相同的记录,如果我想左连接查2个表中book_num不一样的记录,请问如何实现,谢谢!
...全文
60 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fa_ge 2007-11-29
  • 打赏
  • 举报
回复

1.建立一个一模一样的数据表,就数据表名不一样?
select * into tb1 from tb2 where 1=0

2如果我想左连接查2个表中book_num不一样的记录,请问如何实现,

select * from t1 where id not in(select id from t2)
or
select * from t2 where id not in(select id from t1)
dawugui 2007-11-29
  • 打赏
  • 举报
回复
1.建立一个一模一样的数据表,就数据表名不一样?
select * into tb1 from tb2

2.如何合并查询,如何查不符合条件的记录....例如:
select a.*,b.bj,b.i_date from book1 a left outer join book2 b on a.book_num=b.book_num
上面这句是查询,是左连接查询a表和b表中book_num相同的记录,如果我想左连接查2个表中book_num不一样的记录,请问如何实现,谢谢!

select a.* from book1 where book_num not in (select book_num from book2)
select a.* from book2 where book_num not in (select book_num from book1)

34,838

社区成员

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

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