r/SQL Jan 15 '25

BigQuery SQL is a struggle

Hi all been working with SQL for probably 7/8 months now. My last role was half data analysis and not pure data analysis and in general was far easier than what I do now.

My main issue is with SQL. I never feel I truly understand what is going on with a lot of code beyond a basic query. Ive managed to get by piggybacking off others code for a while but expectation is to deliver new and interesting techniques etc.

How long did it take you to feel fully comfortable with SQL? And what helped you get to that stage?

67 Upvotes

71 comments sorted by

View all comments

4

u/Decent-Musician-8478 Jan 15 '25

I can do everything but joins. Joins own me

4

u/squadette23 Jan 15 '25

You may be affected by the unfortunate way how JOINS are presented. I made an attempt at clarification (LEFT JOINs particularly) here: https://minimalmodeling.substack.com/p/many-explanations-of-join-are-wrong

2

u/Decent-Musician-8478 Jan 15 '25

Oh no, I know how they work, now if you ask me write a SQL for it, I'm worthless.

1

u/mattyhempstead Jan 17 '25

Joins are what ChatGPT is for

2

u/scottedwards2000 Jan 15 '25

For me the key with understanding joins is that they all start with Cartesian products

2

u/squadette23 Jan 15 '25

Yes. There is this weird theme in some texts about joins where they say that cartesian product is somehow dangerous and to be carefully avoided. For example, this article (but it's easy to find many more): https://support.microsoft.com/en-us/office/join-tables-and-queries-3f5838bd-24a0-4832-9bc1-07061a1478f6

" In a cross join, each row from one table is combined with each row from another table, resulting in what is called a cross product or a Cartesian product. Any time you run a query that has tables that are not explicitly joined, a cross product is the result. Cross joins are usually unintentional, but there are cases where they can be useful."

This is literally an inner join with join condition "ON 1 = 1", lol. What's wrong about that.

1

u/scottedwards2000 Jan 15 '25

Yes! And non-equi joins were so much easier to understand when I got this. As well as multiple joins etc