三表合并查询的问题

bighai 2005-01-07 02:46:57
t_news(表1)
c_no //主键
c_title
c_content
c_date


t_office(表2)
c_no //主键
c_3title
c_content
c_date

shop_news(表3)
newsid //主键
newsname
newscontent
adddate


现在想合并成一个表查询!
请高手指点,如果能得到类似的技术文档或例题更好!
...全文
259 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
lvf20 2005-01-11
  • 打赏
  • 举报
回复
select c.*,b.*,c.* from c
left outer join b on b.id=c.id
left outer join a on c.id=a.id

行不行?
long_205 2005-01-10
  • 打赏
  • 举报
回复
select c_title,c_content,c_date from t_news
union all
select c_3title,c_content,c_date from t_office
union all
select newsname,newscontent,adddate from shop_news
here4u 2005-01-10
  • 打赏
  • 举报
回复
搂住想要什么样的查询结果呢?
bighai 2005-01-10
  • 打赏
  • 举报
回复
请问用innerjoin具体怎么写?我很菜哦,能不帮忙写完整?
OYHL 2005-01-10
  • 打赏
  • 举报
回复
没有什么意思t_news(表1)
c_no //主键

t_office(表2)
c_no //主键
shop_news(表3)
newsid //主键
//////////////////////////t_news innerjoin t_office on
//////////////////////////t_news innerjoin shop_news
//////////////////////////where
就是个多表查询
631799 2005-01-07
  • 打赏
  • 举报
回复
select * from 表1,表2,表3
bighai 2005-01-07
  • 打赏
  • 举报
回复
用union肯定不行
bighai 2005-01-07
  • 打赏
  • 举报
回复
按楼上的方法测试不行,报错说列的数目不相等!
表1和表2的列的数目和字段类型是一样的,但表3列的数目与这表1表2不一样,字段的类型也不一样!
Softlee81307 2005-01-07
  • 打赏
  • 举报
回复
select * from
(select * from t_news(表1)
union
select * from t_office(表2)
union
select * from shop_news(表3)) a
------------------------------
where 條件.... " 這句是加查詢條件的可省不做
bighai 2005-01-07
  • 打赏
  • 举报
回复
上面的方法只是嵌套查询的,并不是合并查询的,我测试过了,求最终解决办法
ReViSion 2005-01-07
  • 打赏
  • 举报
回复
这要看以哪个为主表
(这里的主从次序为a,b,c Id为各表主键)

select c.*,b.*,c.* from c
join b on b.id=c.id
join a on c.id=a.id

xluzhong 2005-01-07
  • 打赏
  • 举报
回复
select a.*,b.*,c.* from 表1as a,表2 as b,表3 as c
where a.c_no=b.c_no and a.c_no=c.newsid and.....条件


或:
join


F1
bighai 2005-01-07
  • 打赏
  • 举报
回复
搜索了一下例子看了,好像用join可以,但不知道在我这种情况下怎么用?
bighai 2005-01-07
  • 打赏
  • 举报
回复
字段类型不一样哦!
viptiger 2005-01-07
  • 打赏
  • 举报
回复
如果字段类型一样可以
select c_title,c_content,c_date from t_news
union all
select c_3title,c_content,c_date from t_office
union all
select newsname,newscontent,adddate from shop_news
WangZWang 2005-01-07
  • 打赏
  • 举报
回复
如:
select a.*,b.*,c.* from 表1as a,表2 as b,表3 as c
where a.c_no=b.c_no and a.c_no=c.newsid and.....条件

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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