Question: This is the answer I was given to my question what is the difference between union and join in sql? but I am having a

This is the answer I was given to my question "what is the difference between union and join in sql?" but I am having a hard time understanding the answer. Could you please explain the answer to me, and if possible provide a visual example of how each is used. I found a visual example online using colored blocks but I do not understand that either. This is the answer I was given to my question "what is

ANSWER GIVEN to what is the difference between union and join

JOINs, can be used to retrieve data from two or more tables based on logical relationships between the tables.

When two tables are joined together, then the data from the first table is shown in one set of column whereas the second tables column is also displayed in the same row alongside.

UNION combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union.

If two tables are combined together using union, then the data from the first table is in one set of rows, and the data from the second table in another set.

Save Table B Result Joins Combine Columns Each row in the result contains columns from BOTH table A and B. Rows are created when columns from one table match columns from another. This match is called the join condition This makes joins really great for looking up values and including them in results. This is usually the result of denormalizing (reversing normalization) and involves using the foreign key in one table to look up column values by using the primary key in another Now compare the above depiction with that of a union. In a union each row within the result is from one table OR the other. In a union, columns aren't combined to create results, rows are combined Table A Table B Result

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!