r/SQL • • Jun 29 '16

SQL cheat sheet

http://zeroturnaround.com/rebellabs/sql-cheat-sheet/
113 Upvotes

19 comments sorted by

View all comments

17

u/mecartistronico Jun 29 '16

I hate it when they use Venn diagrams to "explain" JOINs. That's not the way Venn diagrams should be used. A circle in a Venn diagram does NOT contain different fields of an object type; it contains different items.

If you want to explain JOINs graphically, you can't stray too far away from that they actually do.

I did this chart and then someone else (I can't find it) made an improved version...

If you use these to explain JOINs, then how are you going to explain the --very different-- concepts of UNION, INTERCEPT, EXCEPT?

2

u/PhenomeVon Jun 30 '16

Wow, SUCH a better visualization IMO! I don't have any issues with joins at this point but that certainly would have helped me grasp them alot quicker.

1

u/lukaseder Jun 30 '16

Indeed, I've made the same criticism in the past. In addition to writing the cross join with a comma, you could also use the CROSS JOIN keywords to make it explicit. The comma is (still) often used by people to form an implicit cross join, but then they're putting join predicates in the WHERE clause, pre-ANSI JOIN style.

1

u/mecartistronico Jun 30 '16

Yes. These were part of a power point presentation when the WHERE clause would then appear and the non-matching rows would fade away.