TGViewer
Data Analysis Books | Python | SQL | Excel | Artificial Intelligence | Power BI | Tableau | AI Resources Data Analysis Books | Python | SQL | Excel | Artificial Intelligence | Power BI | Tableau | AI Resources @learndataanalysis · 53.3K subscribers
Post #2052 3.21K
✅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!
  • ❤ 8
More from @learndataanalysis
  1. Sep 23, 2026✅ Types of Machine Learning Algorithms 🤖📊 1️⃣ Supervised Learning Supervised learning me…
  2. Sep 19, 2026🚀 GigaChat 3.5 Reasoning — a new open-source LLM that thinks before it answers. It breaks…
  3. Sep 16, 2026🟠 Part 12 — Dashboard Development • Dashboard layout, Tiled vs Floating, Containers, Devi…
  4. Sep 16, 2026📊 Tableau Learning Roadmap 2026 If you're starting Tableau from scratch, follow this orde…
  5. Sep 6, 2026UNPOPULAR OPINION: Excel is still relevant for data analysis. I am often asked by junior d…
  6. Aug 28, 2026✅ Power BI Basics 📊🚀 👉 Power BI is one of the most popular Business Intelligence BI too…
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 →