TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation · 5.9K subscribers
Post #1344 390
📊 SQL SATURDAY #1 - The Basics, Done Right

Let's start simple but do it properly. Here's our table:


employees
+----+----------+------------+--------+
| id | name | department | salary |
+----+----------+------------+--------+
| 1 | Alice | Engineering| 95000 |
| 2 | Bob | Sales | 62000 |
| 3 | Charlie | Engineering| 105000 |
| 4 | Diana | Marketing | 70000 |
+----+----------+------------+--------+


Question: Find all employees in Engineering earning more than 100,000.

sql
SELECT name, salary
FROM employees
WHERE department = 'Engineering'
AND salary > 100000;


Simple, right? But here's the interview trap:

⚠️ Common pitfall: People forget WHERE runs before SELECT logically, so you can't reference a column alias defined in SELECT inside your WHERE clause.

sql
-- This will ERROR in most databases:
SELECT salary * 1.1 AS new_salary
FROM employees
WHERE new_salary > 100000; -- ❌ new_salary doesn't exist yet here


Fix it by repeating the expression or using a subquery/CTE. We'll get into CTEs in a few weeks 👀

What's a SQL mistake that tripped you up early on? 😅
  • ❤ 6
More from @coding_interview_preparation
  1. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  2. Oct 6, 2026document post
  3. Oct 4, 2026💼 Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  4. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  5. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
  6. Sep 30, 2026💼 What Companies Actually Look For in a Fresher Think companies only care about your CGPA…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →