Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Querying Relational Databases Set Operations Union Operations

Unions require the number of columns...


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 Peak
Balazs Peak
46,160 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,681 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.