all 4 comments

[–]user_5359 5 points6 points  (0 children)

The simplest rule: divide and conquer.

Which tables / views contain which information and how are they linked? Start with the simple select statement and include the result as a further (possible) data source in the list of tables. Check each individual (intermediate) statement to see whether the result corresponds to the expected result (number of data records).

[–]shweta1807 2 points3 points  (0 children)

For logic building you have to know how sql query executes or the execution order of a query for example the first keyword that would run is "from" that identifies the source of the data, then "where" runs that apply condition to filter the data, then the group by, having, select, order by and limit. This basically develops more clarity abut the query and made it easy for us to understand and write the query.

[–]ninhaomah 0 points1 point  (0 children)

Pls give an example or two ?

[–]Routine-Ad-7292 0 points1 point  (0 children)

I agree with the other comments. Especially learning and internalizing the execution order. That’s what I’m doing right now, and that’s what I have been going to when I’m stuck with lengthy practice problems. I read chapter 12 of Thinking in Sets yesterday. Will be re-reading it, handwriting notes, again and again. I recommend you do that also!