Hi..
Have a tricky question here. Your help is appreciated !
I have 3 tables as below
TABLE A
DEPT_NBR MGT_NBR MGR_NAME
1 111 ABD
6 222 XXX
2 33 RRR
4 444 JJJJ
3 555 DDDD
7 77 NNNN
TABLE B
EMP_NBR EMP_NAME DEPT_NBR MGR_NBR
1 DON 1 111
2 HARI 5 33
3 RAMESH 3 555
4 JOE 2 33
5 DENNIS 2 33
6 NIMISH 4 444
TABLE C
DEPT_NBR DEPT_NAME MGR_NBR
1 FINANCE 111
2 HR 33
3 ADMIN 555
4 PROJECT 444
5 WFM 33
7 PMO 77
My requirement is to extract the rows in Table A which has no overlaps in both Tables B and C.
I have the used NOT EXISTS for the extraction
SELECT MGR_NAME
FROM TABLE A
WHERE NOT EXISTS
( SELECT DEPT_NBR,MGR_NB R FROM TABLE B )
AND NOT EXISTS
( SELECT DEPT_NBR,MGR_NB R FROM TABLE C )
Q1 ) Would like to know if there is an option to use JOIN instead of NOT
EXISTS and the extract he same output in a single query.
Q2) Can JOIN command be used ON multiple columns. For example, in this case is there a syntax to join on both Dept no and Manager no ? I need both to be used in the JOIN option and not one of them in the WHERE clause.
Have a tricky question here. Your help is appreciated !
I have 3 tables as below
TABLE A
DEPT_NBR MGT_NBR MGR_NAME
1 111 ABD
6 222 XXX
2 33 RRR
4 444 JJJJ
3 555 DDDD
7 77 NNNN
TABLE B
EMP_NBR EMP_NAME DEPT_NBR MGR_NBR
1 DON 1 111
2 HARI 5 33
3 RAMESH 3 555
4 JOE 2 33
5 DENNIS 2 33
6 NIMISH 4 444
TABLE C
DEPT_NBR DEPT_NAME MGR_NBR
1 FINANCE 111
2 HR 33
3 ADMIN 555
4 PROJECT 444
5 WFM 33
7 PMO 77
My requirement is to extract the rows in Table A which has no overlaps in both Tables B and C.
I have the used NOT EXISTS for the extraction
SELECT MGR_NAME
FROM TABLE A
WHERE NOT EXISTS
( SELECT DEPT_NBR,MGR_NB R FROM TABLE B )
AND NOT EXISTS
( SELECT DEPT_NBR,MGR_NB R FROM TABLE C )
Q1 ) Would like to know if there is an option to use JOIN instead of NOT
EXISTS and the extract he same output in a single query.
Q2) Can JOIN command be used ON multiple columns. For example, in this case is there a syntax to join on both Dept no and Manager no ? I need both to be used in the JOIN option and not one of them in the WHERE clause.
Comment