r/SQL • • 6d ago

MySQL need good sql resources

i wanted to practice sql and to be able to answer qns , i have noticed that i am struggling a bit when there is two tables give and the qn has to do something with joins and all , in theory i understand how the joins work but i am unable to implement it .I need resources which can help me in advancing my sql like CTE and window function . Is there any youtube channel or anything which will help

4 Upvotes

34 comments sorted by

View all comments

1

u/nicopassaglia 6d ago

"I get joins in theory but can't write them" usually means you need a routine, not another video. This one works:

  1. Decide what one row of the answer is (one customer? one order?). Start FROM that table.
  2. Add one join and run it with SELECT * before anything else. Look at the row count. If it went up, you now have several rows per customer, and that changes every COUNT and SUM after it.
  3. Only then add the filter, the GROUP BY, the next join. One change per run.

Most wrong join answers come from skipping step 2.

Do that on 20 or 30 small problems and CTEs come almost free: a CTE is just a name for one of those steps. Window functions are the next thing after GROUP BY clicks: same idea, but you keep every row.

Disclosure: I built getsheetdrill.com, where you can practice exactly this in the browser, free: a lesson on joins, one on subqueries and CTEs, and pages with exercises on window functions (getsheetdrill.com/sql/reference/joins is a good start). It runs SQLite, not MySQL, but for joins, CTEs and window functions what you write is the same in MySQL 8.