TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2290 7.57K
✅10 Most Useful SQL Interview Queries (with Examples) 💼

1️⃣ Find the second highest salary:
SELECT MAX(salary)  
FROM employees 
WHERE salary < (SELECT MAX(salary) FROM employees);


2️⃣ Count employees in each department:
SELECT department, COUNT(*)  
FROM employees 
GROUP BY department;


3️⃣ Fetch duplicate emails:
SELECT email, COUNT(*)  
FROM users 
GROUP BY email 
HAVING COUNT(*) > 1;


4️⃣ Join orders with customer names:
SELECT c.name, o.order_date  
FROM customers c 
JOIN orders o ON c.id = o.customer_id;


5️⃣ Get top 3 highest salaries:
SELECT DISTINCT salary  
FROM employees 
ORDER BY salary DESC 
LIMIT 3;


6️⃣ Retrieve latest 5 logins:
SELECT * FROM logins  
ORDER BY login_time DESC 
LIMIT 5;


7️⃣ Employees with no manager:
SELECT name  
FROM employees 
WHERE manager_id IS NULL;


8️⃣ Search names starting with ‘S’:
SELECT * FROM employees  
WHERE name LIKE 'S%';


9️⃣ Total sales per month:
SELECT MONTH(order_date) AS month, SUM(amount)  
FROM sales 
GROUP BY MONTH(order_date);


🔟 Delete inactive users:
DELETE FROM users  
WHERE last_active < '2023-01-01';


✅ Tip: Master subqueries, joins, groupings & filters – they show up in nearly every interview!

💬 Tap ❤️ for more!
  • ❤ 22
  • 👍 3
  • 👏 2
  • 🥰 1
More from @sqlspecialist
  1. Oct 14, 2026I could then categorize customers into groups such as Active, At Risk, and Inactive and su…
  2. Oct 14, 2026📊 Data Analyst Interview Series — Part 10 Guys, let's continue our Data Analyst Interview…
  3. Oct 13, 2026📊 Data Analyst Interview Series — Part 9 Guys, let's continue our Data Analyst Interview…
  4. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  5. Oct 12, 20268️⃣ You receive a dataset with inconsistent date formats. How would you clean it? Sample A…
  6. Oct 12, 2026📊 Data Analyst Interview Series — Part 7 Guys, let's continue our Data Analyst Interview…
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 →