SQL A:
select * from tableA
where exists (select * from tableA a, tableB b where a.pk_a=b.pk_a and tableA.pk_x=a.pk_x)SQL B:
select * from tableA
where exists (select * from tableA a inner join tableB b on a.pk_a=b.pk_a and tableA.pk_x=a.pk_x)在Oracle10g中执行上述两段语句,发现SQL A能够正常执行,但执行SQL B时,却报找不到字段tableA.pk_x。
请问,如何解释这一现象?另,上述两段代码在SQL Server中均能够正常执行。
select * from tableA
where exists (select * from tableA a, tableB b where a.pk_a=b.pk_a and tableA.pk_x=a.pk_x)SQL B:
select * from tableA
where exists (select * from tableA a inner join tableB b on a.pk_a=b.pk_a and tableA.pk_x=a.pk_x)在Oracle10g中执行上述两段语句,发现SQL A能够正常执行,但执行SQL B时,却报找不到字段tableA.pk_x。
请问,如何解释这一现象?另,上述两段代码在SQL Server中均能够正常执行。
select * from tableA c
where exists (select * from tableA a inner join tableB b on a.pk_a=b.pk_a where tableA.pk_x=a.pk_x);
where exists (select * from tableB b where a.pk_a=b.pk_a );
就行,或者直接内连接如果一定要在exists用2个表
只能用where,才可以跟外表关联join 后的on和and条件 只能引用 join两边的表select * from tableA c
where exists (select * from tableA a inner join tableB b on a.pk_a=b.pk_a where c.pk_x=a.pk_x)
;
谢谢大家的帮助。
2 where exists (select * from emp a inner join dept b on a.deptno=b.deptno where emp.deptno=a.deptno);
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7902 FORD ANALYST 7566 1981-12-3 3000.00 20
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20
7566 JONES MANAGER 7839 1981-4-2 2975.00 20
7369 SMITH CLERK 1000 1980-12-17 800.10 20
7900 JAMES CLERK 7698 1981-12-3 950.00 30
7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30
7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30
7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30
7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30
7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30
7934 MILLER CLERK 7782 1982-1-23 1300.00 10
7839 KING PRESIDENT 1981-11-17 5000.00 10
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
14 rows selected