Fork me on GitHub
#sql
<
2023-06-02
>
Lennart Buit20:06:04

Does all things SQL include… how to get better at SQL? What courses/books/video tutorials do you guys suggest to elevate your SQL foo?

Lennart Buit20:06:42

Very interesting! From my 1 minute scan, thats about perf, right? I am also very interested in writing more advanced queries

isak21:06:16

Yea, true. For learning about more advanced queries, I read/skimmed a few books such as this: https://www.amazon.com/T-SQL-Window-Functions-Developer-Reference-dp-0135861446/dp/0135861446/ref=dp_ob_title_bk Though that one is is for SQL Server, not sure what you use.

isak22:06:39

But lately I'm not sure it is worth it, because it seems performance falls over so easily for complex queries

Lennart Buit22:06:27

Postgres. Ironically I’ve been looking at whether we can leverage the database more :’).

🙂 2
slipset10:06:21

I think that a curious mindset is valuable too. Asking “I wonder if I could do this in my database rather than in my application code” gets you a long way .

slipset10:06:37

Getting familiar with PARTITION BY , common table expressions, remembering that you can have sub-queries almost all over the place are things that might help

slipset10:06:13

eg select (select bar from foo where foo.id = id) from baz where qix = 'qux' is an example of a neat trick which lets you write more composable queries which is a huge win when working with #C66EM8D5H

mauricio.szabo21:06:44

Remember that asking yourself "can I do this on my database" the answer usually is "yes", so try to not fall too deep into a rabbit hole, like trying to solve the Advent of Code in pure SQL: https://gitlab.com/mauricioszabo/advent-of-code-2021/-/tree/master/src :rolling_on_the_floor_laughing:

🙂 2
mauricio.szabo21:06:57

The last day I dared it's basically an adapted version of the "A* Pathfinding" algorithm, but I never made it so it performed well to solve the second part of the challenge...

isak22:06:40

I think it is a really great way to learn. E.g., create a sudoku solver in Clojure, then try it in SQL.

mauricio.szabo22:06:09

Also I remember something I learned quite early - somebody was explaining SQL and he said: "SQL Hates Loops! Transform everything into tables and join, filter them, but don't do loops!" Another thing is to learn how to use EXPLAIN - might save a lot of time debugging things

Lennart Buit09:06:27

can I and should I do this in SQL, haha

2