| how to get unmatched record from emp and dept tables [message #635391] |
Sun, 29 March 2015 08:48  |
 |
ursfriend77
Messages: 6 Registered: February 2011 Location: Bangalore
|
Junior Member |
|
|
Hi,
I want to get unmatched record from emp and dept tables. This is interview question,i tried using full outer join but using full outer i was getting matched and unmatched record,but my scenario is i have to get only unmatched record my 2 tables(emp and dept)
Thanks
Venki
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: how to get unmatched record from emp and dept tables [message #635437 is a reply to message #635433] |
Mon, 30 March 2015 05:27   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
vippysharma wrote on Mon, 30 March 2015 15:46@ursfriend77..
Use MINUS set operator but do remember, Both tables should have same no of columns.
It is already suggested by others above.
Quote:if mismatch use null as column
Wouldn't that return all the rows for the first query, unless there is an exact match for the NULL values for the columns mentioned in the column list in the respective order in both queries. Or, vice-versa, you could get rows filtered out for the NULL values.
The number of columns and their data types need to be same in the column_list of the SELECT query.
For example,
SQL> SELECT deptno FROM emp
2 MINUS
3 SELECT deptno FROM dept
4 /
no rows selected
But, if you just add NULL as you said, it would return different output:
SQL> SELECT deptno, comm FROM emp
2 MINUS
3 SELECT deptno, NULL FROM dept
4 /
DEPTNO COMM
---------- ----------
30 300
30 500
30 1400
SQL>
So, you just need to maintain the matching number of columns and their datatypes in correct order in both the queries, not that tables need to have same number of columns.
Edit : Oops, I edited using back button so two posts got submitted. Deleting the duplicate post.
[Updated on: Mon, 30 March 2015 05:41] Report message to a moderator
|
|
|
|
|
|
|
|
|
|