楼主不是要得到T1里p_name=370 在p_id=u_id的情况下,u_name也是370吗?
解决方案 »
- 如何使用select case实现下面的逻辑啊?
- 哪位高手指点下!oracle菜鸟关于存储过程中编写循环的问题!!!!急!+急+++++++++急!!!!!
- 为什么不能安装ORACLE 8I
- 请教一个删除的SQL语句问题
- windows2000中Oracle OEM 的登录问题
- 100分求解 ,在线等待
- 请问各位大虾,如何在ORACLE73的初始化文件中写上两个归档目录,即log_archive_dest的路径有两个时怎么办?
- 怎么样在Oracle中取得刚刚新增,修改,删除的记录.
- 有办法操作远程ACCESS数据库吗?
- 数据库扩容
- start with... connect by ...语句性能优化
- PL/SQL developer里怎么查看游标指向的结果集?
union
select * from T2 where u_name=370;--楼主想这样?
p_id p_name
1 370
2 370
3 370
select * from T1 where p_name=370
union
select * from T2 where u_name=370;--union 的作用是去掉重复的记录
我想得到的是T1.p_name='370' or (T2.u_name='370' and T2.u_id在T1.p_id里)。
大家快帮帮我吧!
union
select * from T2 where u_name=370 where u_id in (select p_id from T1 );--u_id在T1的p_id里,而不需要相等?
对,要求u_id在T1的p_id里出现!
select * from T1 where p_name=370
union
select * from T2 where u_name=370 and u_id in (select p_id from T1 );
select p_id from T1 where p_name=370
union
select u_id from T2 where u_name=370 and u_id in (select p_id from T1 );
但是只能取得p_id这一个字段的值啊,能不能把t1里的所有字段都取出来?如果用*号就报错。说是字段不匹配!!!
union
select * from T2 where u_name=370 and u_id in (select p_id from T1 );
--用这个是可以的,不会是你p_name和u_name的字段类型不同吧?
--执行
select * from T1 where p_name=370
union
select * from T2 where u_name=370 and u_id in (select p_id from T1 );
--结果:我没发现有什么错的地方 P_ID P_NAME
---------- ----------
1 370
2 370
3 370
select a.p_id,a.p_name,b.p_id,b.p_name from T1 a,T2 b where a.p_id=b.p_id and a.p_name=370 and b.p_name=370 group by a.p_id,a.p_name,b.p_id,b.p_name
from (
select p_id as id,p_name as name
from t1
where p_name='370'
)
unit
(
select u_id as id,u_name as name
form t2
where p_name='370'
)