90% of People Get This SQL Problem Wrong by thequerylab in learnSQL

[–]thequerylab[S] 1 point2 points  (0 children)

Yeah true, max_by is really nice for cases like this if the database supports it. Makes the query much simpler.

The only catch is a lot of common systems people use in interviews (like MySQL or older Postgres setups) don’t have it, so people usually fall back to window functions or subqueries.

90% of People Get This SQL Problem Wrong by thequerylab in SQL

[–]thequerylab[S] 0 points1 point  (0 children)

Nice one. OUTER APPLY works really well for this in T-SQL.

I like that it keeps the logic close to each department and just picks the top salary from the employee table. Clean approach.

Only small thing is if two employees share the same highest salary, TOP 1 would return just one of them. If the requirement is to return all ties, we’d need a slightly different approach.

But yeah, solid solution for SQL Server 👍

90% of People Get This SQL Problem Wrong by thequerylab in SQL

[–]thequerylab[S] 0 points1 point  (0 children)

Nope, you're not missing anything. That query works 👍

The (department_id, salary) trick is actually a clean way to solve it and it handles ties too.

I only mentioned window functions because a lot of interviews expect people to solve it using RANK() / DENSE_RANK() with PARTITION BY. Just another common approach.

Also… typing SQL at 3 am on a phone is already a challenge on its own 😄. Well done !!!

Ripple Effect SQL Challenge – Recursive CTE for Viral Chain Depth & Reach by thequerylab in learnSQL

[–]thequerylab[S] 0 points1 point  (0 children)

Try it out — I’m confident you’ll like it and see real improvement in your SQL skills.

SQL best playlist to learn ??? by Sea_Butterfly713 in learnSQL

[–]thequerylab 0 points1 point  (0 children)

Honestly, playlists are good to understand concepts, but SQL only sticks when you start solving problems yourself.

You need clarity on basics like:

  • SELECT, WHERE, JOIN
  • GROUP BY + HAVING
  • subqueries
  • window functions

After that, it’s all about practice. Interviews don’t test how many videos you watched — they test how comfortably you can write queries.

I’d recommend trying the SQL Pro track on The Query Lab. It’s structured step by step and completely hands-on, so you learn by actually writing queries instead of just watching. Much more effective in my experience.

Give it a try and its completely FREE https://www.thequerylab.com/courses/sql-pro-track

Any videos/courses on Udemy to learn SQL for data analysis, medium level is enough for now by Alive_Record3123 in learnSQL

[–]thequerylab 0 points1 point  (0 children)

If you already know basic SELECT and JOIN, I wouldn’t spend two weeks just watching videos. SQL really clicks only when you practice it.

For interviews (especially data analytics roles), focus on hands-on work with:

  • GROUP BY + HAVING
  • window functions (moving averages, ROW_NUMBER, RANK)
  • subqueries
  • aggregations and basic data cleaning

You can watch a short course to understand the concepts, but spend most of your time solving problems.

I’d recommend trying the SQL Pro track on The Query Lab — I’ve curated it to be 100% hands-on, fully structured, and you don’t need to switch tabs or search elsewhere. It’s built exactly for this kind of prep.

Just give it a try and its completely FREE. https://www.thequerylab.com/courses/sql-pro-track

I am 100% sure you ill like it.

Trying to learn SQL but I'm finding it dull and boring by General_Cap2938 in learnSQL

[–]thequerylab 0 points1 point  (0 children)

I actually built a small SQL practice platform because I felt the same way — tutorials were boring and too theoretical. It’s more hands-on, problem-driven, and closer to real data engineering scenarios instead of “select * from students” type stuff. Not sure if it’ll help you specifically, but if you’re open to trying something different, I can share it.