如:
SQL> select * from a;ID ST C D
---- -- -- ----
11 2 19 48
12 2 29 58
13 2 39 68SQL> select * from b;ID ST C D
---- -- -- ----
19 11 y 48
29 11 n 48
39 11 y 48
119 12 y 58
129 12 n 58
139 12 y 58已选择6行。
SQL> select id,(select max(c) from b where b.status=a.id) from a;ID (S
---- --
11 y
12 y
13SQL>
SQL> select * from a;ID ST C D
---- -- -- ----
11 2 19 48
12 2 29 58
13 2 39 68SQL> select * from b;ID ST C D
---- -- -- ----
19 11 y 48
29 11 n 48
39 11 y 48
119 12 y 58
129 12 n 58
139 12 y 58已选择6行。
SQL> select id,(select max(c) from b where b.status=a.id) from a;ID (S
---- --
11 y
12 y
13SQL>
(select name2 from tableB where tablea.name=tableb.name) as b FROM tableA where id='1203';
也就是a 有1、2、3 当a=1、name2的值,a=2时name2的值匹配显示?我不清楚是不是可以!!
FROM tableA left outer join tableB on tableA.name=tableB.name
where id='1203';
FROM tableA left outer join tableB on tableA.name=tableB.name
where tableA.id='1203';
(select name2 from tableB where name=a) as b FROM tableA where id='1203'
我想将外部得到的a的值,作为内部SQL的一个参数条件
当a=1是括号内SQL应为(select name2 from tableB where name='1')
当a=2是括号内SQL应为(select name2 from tableB where name='2')
FROM tableA.name=tableB.name(+)
where tableA.id='1203'
SELECt name as a,
(select name2 from tableB where name=a) as b FROM tableA where id='1203'
1、在内部SQL还有其他的条件,
SELECt name as a,
(select name2 from tableB where name=a and myid='001') as b FROM tableA where id='1203'
2、tableA的name,在tableB中会对应几条记录或没有记录,但不管怎样tableA的name都要显示!!
3、用外联结要显示多余的记录!!
SELECt name as a,
(select max(name2) from tableB where name=a) as b FROM tableA where id='1203'
方法二:
select a.name a,b.name2 from tablea a,tableb b where a.a=b.name(+) and a.id='1203';
这样的话全部显示用嵌套是不允许的比如这是那两个表:
SQL> select * from a;ID ST C D
---- -- -- ----
11 2 19 48
12 2 29 58
13 2 39 68SQL> select * from b;ID ST C D
---- -- -- ----
19 11 y 48
29 11 n 48
39 11 y 48
119 12 y 58
129 12 n 58
139 12 y 58已选择6行。你想得到什么样的结果?
SQL> select * from a;ID lxid C D
---- -- -- ----
11 2 19 48
12 2 29 58
13 2 39 68SQL> select * from b;ID ST C name
---- -- -- ----
11 fd f name1
11 dd dd name1
12 22 ss name1
11 dd ff name2
12 fa ff name2
13 ff ff name2
得到的在a 表lxid相同情况下,显示所有a.id,b.name, 条件:表b的name=name1
ID不能重复,显示所有a.id b表的id没有13,name应显示null