I was going through the Learning SQL 2nd Edition book. Is there any difference between the SET operations and the JOIN.Are there any situations where you would go with SET operations leaving JOIN.
Correct me if i am wrong, we can do all the things using JOIN what we can do with SET.
No, you cannot do all the things with a
jointhat you can do with the set operations. However, if two tables have the same structure and have unique identifiers on each, then you can:A
unionwould be:The
exceptandintersectcan be approached in the same way, but putting conditions on thefull outer joinin the driver table.In fact, you can extend this idea to not require a unique id, just assuming that the rows are unique in each table. In that case, the joins are more complicated, because you have to include all columns, and also take into account NULL values in the columns.
That said, the
setoperations have several advantages:unionandunion allare much more readable than the above queries.unionandintersect.