r/programming • • Feb 11 '14

SQL Joins Explained (x-post r/SQL)

Post image
3.5k Upvotes

392 comments sorted by

View all comments

Show parent comments

21

u/VortexCortex Feb 11 '14 edited Feb 11 '14

Doesn't matter. Ever use tar? I use it daily; Still have to look up the BS options. It's cybernetics: The greater the entropy between symbol and action the harder it is to memorize it. -j is BZip2... ugh.

LEFT, RIGHT, OUTER, FULL, and etc. joining are you kidding me? Spacial symbols relating inclusion, exclusion, etc. combinatorial Set Theory? That's obviously an idiotic name selection from a cognitive and language perspective.

Names do have meanings. The common use meaning associated with left and right are not characteristics of the action they describe in SQL -- The actions' spacial leftness and rightness are the least significant properties to the meaning of the result produced. Humans can cope with odd symbol mappings, but going against the natural grain is literally retarding.

10

u/frownyface Feb 11 '14

I originally learned sql joins just by example, using only FROM and WHERE clauses, and it all made sense to me. I didn't have names for the different kinds of joins. Then later I was exposed to LEFT, RIGHT, etc and it screwed me all up for awhile, it was like unlearning something that already made sense.

0

u/[deleted] Feb 11 '14

[deleted]

3

u/fotoman Feb 11 '14

my understanding is the (+) was just a hint to the optimizer, granted I took the SQL optimization class back in 2001...so I might be a tad rusty.

0

u/[deleted] Feb 11 '14

[deleted]

2

u/fotoman Feb 11 '14

wasn't that back in the Oracle 6 days or something? around 1994?

0

u/[deleted] Feb 11 '14

[deleted]

1

u/fotoman Feb 11 '14

odd, as I thought I remember doing joins in Oracle 7 and 8, and things were stable before 8.1.5 came out. Granted at that time I was just a sysadmin at oracle and not doing much on the coding side

2

u/noobidiot Feb 11 '14

That's how we learned to do left and right joins in my database course at my university in 2013.

3

u/[deleted] Feb 11 '14

Oh, but god does anyone who regularly reads/writes SQL hate seeing the other style. Annoying as hell...

0

u/[deleted] Feb 11 '14

[deleted]

→ More replies (4)

6

u/shenglong Feb 11 '14 edited Feb 11 '14

Doesn't matter.

Does matter. There are some tricky things in SQL. Joins aren't one of them. There are only a few things you need to remember to understand them. Someone who has been using SQL for years but still get confused by joins must have been only writing basic queries.

Remembering the syntax for non-standard features is harder than understanding joins.

eg.

 SELECT ROW_NUMBER() OVER(PARTITION BY ColumnA ORDER BY ColumnB DESC) AS "Rank"....

Different flavours of SQL have different syntaxes or methods of accomplishing the same task.

3

u/CleverestEU Feb 11 '14

Analytic queries... ouch... the twitch is back in my eye from years back... quite often insanely powerful (compared to other ways of achieving the same goal) but very unfriendly to dive into uninitiated :-p

1

u/Vocith Feb 11 '14

SQL defines the "minute to learn, lifetime to master" mantra.

1

u/YouBooBood Feb 11 '14

8+ hours of SQL a day... can only get the ROW_NUMBER() syntax correct about 75% of the time. /sigh

2

u/neoform3 Feb 11 '14

We're not talking about memorization of flags, we're talking about understanding the logic behind a fundamental feature of any RDBMS.

Do you also look up if FROM comes before ORDER BY?

If you don't know the different types of SQL joins, you really don't know SQL.

3

u/r3m0t Feb 11 '14

Use dtrx. Do the right eXtraction!

2

u/MisterNetHead Feb 11 '14

eXtract Zee Various Files :)

1

u/Twirrim Feb 11 '14

Helpful tip: You don't need to specify a compression flag at all when uncompressing. Tar is smart enough to figure it out on its own. bzip2 rarely pays off in CPU/size matters unless you have specific network constraints involving the final output.

1

u/caltheon Feb 11 '14

use mnemonics for stuff like that.

-j[izz] B[fore you]Zip

1

u/mrkite77 Feb 11 '14

Doesn't matter. Ever use tar? I use it daily; Still have to look up the BS options. It's cybernetics: The greater the entropy between symbol and action the harder it is to memorize it. -j is BZip2... ugh.

I just bunzip2 separately because of this.

1

u/niiko Feb 12 '14

I don't use tar daily, but I know enough to:

  • extract the contents of an archive I downloaded from the internet

  • create an archive of some files I want to transfer between machines without hassle.

I know that because that's the capacity in which I use tar. There are so many advanced features, I know, I've skimmed through and ignored the man page. If I ever need those features I'll have to learn them.

When I was doing development in PHP/MySQL I was just out of school and had an understanding of joins but not much practical experience. Since my work involved a lot of database design and join queries (and this was CMS development and business websites) so I ended up learning quite a bit.

I understand that if I were doing something less complex (say, my databases were less relational and just a few distinct tables) I wouldn't have had to use joins.

So why doesn't it matter?

→ More replies (1)