I have two tables and i want to get the difference between them based on the name and the version of the book:
Table 1
id Name version
1 B5077 A
2 B5077 A
4 B5077 B
5 B5077 C
Table 2
id name version
1 B5077 B
2 B5077 C
3 B5077 D
4 B5077 E
SQL command (the result is really fast comparing to a full Join):
( SELECT name, version FROM table 1 where book = 'B5077'
EXCEPT
SELECT name, version FROM table 2 )
UNION ALL
( SELECT name, version FROM table 2 where book = 'B5077'
EXCEPT
SELECT name, version FROM table 1)
It gives me this output:
id name version
1 B5077 A
2 B5077 D
3 B5077 E
but how i can get the id of the line that has the difference and in which table ? so i can have something like this :
id name version idtable1 idtable2
1 B5077 A 1 NULL
2 B5077 A 2 NULL
3 B5077 D NULL 3
3 B5077 E NULL 4
Thanks,