See these two sample tables:
Table 1:
id acc_no name
------------------------
1 14 aaaa
2 16 bbbb
3 18 ccccc
4 25 wwww
5 27 xxxxxxx
6 28 zzzzzzz
Table 2:
sr no acc_no amount
----------------------
1 14 2000
2 16 2344
3 18 3200
I need to get records on basis of acc_no which are not matching in table 1 for example:
OUTPUT:
id acc_no name
---------------------
4 25 wwww
5 27 xxxxxxx
6 28 zzzzzzz
When I tried with below query ,the result was not reliable:
SELECT t1.*
FROM table1 t1
LEFT OUTER JOIN table2 t2 ON t1.acc_no = t2.acc_no
WHERE t2.acc_no IS NULL
Give your suggestions. What will be right SQL query ti get above output?
To find rows that do not match a value, use the NOT operator.
FULL OUTER JOIN returns unmatched rows from both tables,as well as matched rows in both tables.
try:
SELECT *
FROM table1 t1
WHERE t1.acc_no NOT IN (SELECT acc_no FROM table2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With