TGTGInsighttelegram intelligenceLIVE / telegram public index
← Data Analytics
Data Analytics avatar

TGINSIGHT POST

Post #2290

@sqlspecialist

Data Analytics

Views7,320Post view count
PostedSep 1009/10/2025, 05:24 AM
Post content

Post content

✅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!