👨💼 SQL Query to Find Employees Who Didn’t Attend Any Training (LEFT JOIN Example)
In real-world HR and analytics systems, it’s often necessary to identify employees who have not attended any training programs. This type of query is useful in employee engagement analytics, compliance tracking, and HR dashboards.
We’ll use a simple LEFT JOIN approach to find employees with no training records — a method that works in MySQL, SQL Server, Oracle, and PostgreSQL.
🧩 Sample Data
We’ll use two tables — employees and training_attendance.
employees
| employee_id | employee_name | department |
|---|---|---|
| 101 | John Smith | HR |
| 102 | Alice Brown | IT |
| 103 | David White | Finance |
| 104 | Linda Black | Sales |
training_attendance
| training_id | employee_id | training_name |
|---|---|---|
| 501 | 101 | Leadership 101 |
| 502 | 103 | Finance Compliance |
💻 SQL Query: Find Employees Without Training Records
SELECT e.employee_id, e.employee_name, e.department FROM employees e LEFT JOIN training_attendance t ON e.employee_id = t.employee_id WHERE t.employee_id IS NULL;
📊 Output:
| employee_id | employee_name | department |
|---|---|---|
| 102 | Alice Brown | IT |
| 104 | Linda Black | Sales |
✅ Employees Alice Brown and Linda Black have not attended any training sessions.
🔍 Explanation
- The
LEFT JOINreturns all records fromemployees, even if there’s no matching record intraining_attendance. - Rows where
t.employee_idisNULLrepresent employees with no training records. - This approach works for both small HR tables and large corporate datasets.
⚙️ Bonus Tip: Using NOT EXISTS
You can achieve the same result with NOT EXISTS for better performance on indexed tables:
SELECT e.employee_id, e.employee_name, e.department FROM employees e WHERE NOT EXISTS ( SELECT 1 FROM training_attendance t WHERE t.employee_id = e.employee_id );
This version is often faster on large databases and provides the same output.
🚀 Performance Optimization Tips
- Add indexes on
employee_idcolumns in both tables for faster joins. - Use
EXPLAINorQUERY PLANto analyze performance. - For frequent queries, materialize the result set using a view.
📘 Recommended Books to Master SQL & Analytics
- 📗 Learning SQL: Generate, Manipulate, and Retrieve Data, Third Edition
- 🤖 AI Engineering: Building Applications with Foundation Models
- 📊 Storytelling With Data: A Data Visualization Guide for Business Professionals
- 🟡 Microsoft Power BI for Dummies
- 🧩 The Definitive Guide to DAX (2nd Edition)
These books cover everything from SQL fundamentals to business intelligence and Power BI.
🔗 Related SQL Tutorials
- SQL Query to Find Duplicate Records with Different Values
- SQL Query to Calculate Running Total Without Window Functions
- Find Top 3 Salaries Without Using LIMIT or TOP
💬 Join the SQL Community
Want to share your own SQL query or troubleshoot a challenge? Join the conversation at SQLQueries.in Community Forum. Collaborate with SQL experts and grow your analytics knowledge!