The important thing is to understand what happens in the consultation. UNION makes the union of two results removing the duplicities.
I remember that UNION will take into account all the return columns of the query.
Thus, the UNION query will bring a result only field with distinct Ids.
The command mentioned above (represented below) will make a projection between the two tables and will only relate the items of table 1 that does not contain id = in table 2:
SELECT * FROM #t1 tabela1 CROSS JOIN #t2 tabela2 WHERE (tabela1.id <> tabela2.id);
The return of the above query, assuming your example data would be something like:
id tb1 id tb2
1 4
1 5
2 1
2 4
2 5
3 1
3 4
3 5
Tabela1 id 1 only designed with different id’s.
Please put the expected answer to the above example in order to resolve the doubts of those who want to help you.
– anonimo
Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack