Databases Querying Relational Databases Set Operations Union Operations

Unions require the number of columns...

Hi,

I have a question with the last meaning teacher mentioned in this video as followed,

"Unions require the number of columns in your date set to be the same in your first and second table."

What I understand from this meaning is that each table has same number of colums to use UNION. But Make table has 8 columns and ForeignMake table has 9 columns. Then it doesn't make sense with that meaning or theaory.

Did I get wrong with what teacher said?

2 Answers

Balazs Pukli
Balazs Pukli
46,070 Points

I think what he actually meant is sets, not tables. Sets can be represented by result sets as well, not only tables - and you can influence the number of columns in the result set using the query language.

For example, I have two tables, men and women. Women (Id, Age, Shoes, Bags) Men (Id, Age, Weapons)

As you can see, women have one more column, but I can query the 2 first column only with SELECT Id, Age statement from both columns, and have their union.

Also, I can have a union from 2 different result sets from women only. For example, I'm looking for rich women because I want to sell new Hawaii vacations for them. Then I could select women with more than 10 shoes, and women with more than 10 bags, and have the union of those 2 result sets. That union results set would consist of women who have either more than 10 shoes OR more than 10 bags OR both - so they are probably rich, let's sell them the vacation.

Chevy McMartin
Chevy McMartin
9,680 Points

Make has 8 ROWS, and ForeignMake has 9 ROWS. I think you just confused columns with rows.

And Balazs Pukli is right about the sets and tables.