关于sql多表查询的问题.

[复制链接]
查看11 | 回复3 | 2008-1-8 15:36:35 | 显示全部楼层 |阅读模式
如果你希望如下显示valueB/D
3
B的值
3
D的值; ...select 表1.A,表1.B from 表1 where 表1.A=3 union all select 表2.C,表2.D from 表2 where 表2.C=3如果你希望这样显示value B
D3
B的值 D的值那就select t1.A,B,D from (select A,B from a表) as t1 ,(select C,D from b表)as t2 where t1.A='3' and t2.C=t1.A
回复

使用道具 举报

千问 | 2008-1-8 15:36:35 | 显示全部楼层
select * from 表1 where a=3union allselect * from 表2 where c=3你想要的结果是怎样的? 举个例子出来
回复

使用道具 举报

千问 | 2008-1-8 15:36:35 | 显示全部楼层
您好,比如1表的表名是a表,2表的表名是b表select * from (select a,b from a表) as qq ,(select c,d from b表)as pp where qq.a='3' and pp.c='3' 这样可以达到您的要求,我测试过。把(select a,b from a表 )看成一个表叫qq把(select c,d from b表)看成一个表叫ppa,b,c,d就是你原表中的字段不知以上解释您是否能看懂
回复

使用道具 举报

千问 | 2008-1-8 15:36:35 | 显示全部楼层
select * from 表1,表2 where A=3 and c=3
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行