- Fetch all records from Employee table
SELECT * FROM Employee;
- Fetch only employee names
SELECT emp_name FROM Employee;
- Fetch unique department names
SELECT DISTINCT department FROM Employee;
- Fetch employees with salary > 50000
SELECT * FROM Employee WHERE salary > 50000;
- Fetch employees from HR department
SELECT * FROM Employee WHERE department = 'HR';
- Fetch employees with salary between 30000 and 60000
SELECT * FROM Employee WHERE salary BETWEEN 30000 AND 60000;
- Fetch employees in HR or IT
SELECT * FROM Employee WHERE department IN ('HR','IT');
- Fetch employees whose name starts with A
SELECT * FROM Employee WHERE emp_name LIKE 'A%';
- Fetch employees whose name ends with n
SELECT * FROM Employee WHERE emp_name LIKE '%n';
- Fetch employees whose name contains 'ar'
SELECT * FROM Employee WHERE emp_name LIKE '%ar%';
- Fetch employees with NULL manager_id
SELECT * FROM Employee WHERE manager_id IS NULL;
- Fetch employees sorted by salary ascending
SELECT * FROM Employee ORDER BY salary ASC;
- Fetch employees sorted by salary descending
SELECT * FROM Employee ORDER BY salary DESC;
- Fetch top 5 highest paid employees
SELECT TOP 5 * FROM Employee ORDER BY salary DESC;
- Fetch first 5 rows (MySQL)
SELECT * FROM Employee LIMIT 5;
Top SQL Queries for Practice (With Short Answers) - Basic Select Queries (1–15)
ReplyDelete