Tips for SQL?

I’d like to know what your thought process is when you have to write queries to get data.

First, I need a clear mental layout of the tables I want to use. If I don’t have it clear in my head I draw them out.

Then I try to write out in simple sentences (in English) what needs to be connected to get to the target I want.

Then write a hypothesis of what the SQL statements to make those statements work.

If anything goes wrong, break down in what step of the process it was, and go through the process of checking for syntax, concept, implementation errors.

2 Likes

I guess it depends on what questions are asked of the data, or, what you’re trying to glean from the data. Marketing funnel? How many people have canceled subscriptions? How many people leave items in their carts?

Is that what you were referring to?

1 Like

This ^ 100% accurate.

Yes, in a way. But I mostly wanted to just get the thought process behind querying for those things.

Ah, gotcha.
I usually read the question(s)/business requirements several times. :woman_facepalming:t2:

I would write down in my own words what is being asked. (ie: count? aggregating? etc)

I’d also do a cursory look at what’s in the table (like you would w/python: df.head(5)) and:
select * from blah limit 10;

3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.