-1

Possible Duplicate:
Full Outer Join in MySQL

There are two tables tableA and table B both the tables have common column id

We want to get the results which are having all records in A but not in B and all records which exists in B but not in A

Regards, Chinta kiran

Community
  • 1
  • 1
chinta kiran
  • 129
  • 1
  • 1
  • 11
  • 2
    Okay, so what did you try, and what "didn't work"? –  Nov 11 '11 at 09:07
  • We expect you to have attempted to solve this problem by yourself rather than asking the community to arrive at a complete solution for you. When you've got some code to show us that demonstrates some effort by you (even if it's wrong) please update your question and flag to re-open. Thanks. – Kev Nov 11 '11 at 23:45
  • http://stackoverflow.com/search?q=mysql+full+outer+join – Kev Nov 11 '11 at 23:46

4 Answers4

0

You are looking for MINUS SET OPERATOR:

"We want to get the results which are having all records in A but not in B"

Easy way:

SELECT A.*
FROM A 
WHERE A.id not in (SELECT id FROM B)

With Full Outer Join

SELECT A.*
FROM A full outer join B on A.id = B.id
WHERE B.id is Null

The right way:

SELECT A.*
FROM A left outer join B on A.id = B.id
WHERE B.id is Null

Change A to B and B to A for in order to get the results which are having all records in B but not in A.

dani herrera
  • 48,760
  • 8
  • 117
  • 177
0

I suggest you to read the article A Visual Explanation of SQL Joins by Jeff Atwood of Coding Horror.

Full outer join produces the set of all records in Table A and Table B, with matching records from both sides where available. If there is no match, the missing side will contain null.

Sandeep Pathak
  • 10,567
  • 8
  • 45
  • 57
0

You can use UNION operator as follow SELECT * FROM tablea UNION SELECT * FROM tableb if you want to read more about UNION operator

Seder
  • 2,735
  • 2
  • 22
  • 43
0

This is best accomplished with a LEFT OUTER JOIN where the predicate (WHERE clause) ensures that the joined row is NULL; something like:

SELECT A.* FROM A LEFT OUTER JOIN B ON A.id = B.a_id WHERE B.a_id IS NULL;
Greyson
  • 3,598
  • 1
  • 21
  • 22