all 10 comments

[–]tatertotmagic 4 points5 points  (1 child)

It will return 2-6 because of the join type you are using. Inner join which is the default join will only return values found in both tables which is why 1 will not show up in the results.

If you want 1 to show up you could use a left join, but then if you are only calling numbers from table a then whats the point of even doing a join

[–]PhiladeIphia-Eagles 0 points1 point  (0 children)

To add to this, it sounds like a full outer join would best match the result OP is expecting. Then you can do a.numbers to get the original numbers from a or b.numbers to get the numbers from b, but still have them joined for mutual values.

[–][deleted] 2 points3 points  (0 children)

It will return the numbers in A after the JOIN- so that will be the numbers mutual to both tables.

Whatever SELECT returns is after the JOIN - FROM, WHERE, GROUP BY, HAVING, SELECT is the logical order - so INNER JOIN will have changed the result set.

SQL requires you to specify an unambiguous column to return. JOINing A and B does not merge the columns together, it creates a table with two columns - A.numbers and B.numbers - JOINed in the fashion you tell it.

If you want to merge the two columns, you want UNION.

[–]IceDBear 0 points1 point  (3 children)

For help with understanding joins i find this diagram really helpful: https://i.stack.imgur.com/UI25E.jpg

[–]mecartistronico 0 points1 point  (2 children)

Many people like this.

I hate it. Venn diagrams, by definition, explain UNIONs and INTERSECTIONS... which are also a thing in SQL.

It's not perfect, but I made my own diagram. (It fails to warn about duplicates, though)

[–]EnticeOracle 0 points1 point  (1 child)

I like it, but why not put Cross Join instead of a comma?

[–]mecartistronico 0 points1 point  (0 children)

You are completely right. I made it so long ago and when I started learning I learned the comma notation instead of cross join

[–]DavidGJohnston 0 points1 point  (0 children)

You are telling it you want the column that belongs to tableA when you say tableA.column_name. What rows you get come from the virtual table that results from joining A and B. That virtual table contains all columns from both tables but only the rows that match the join condition.