SQL Tutorial 15: Find Employees Hired Before 2020 and Sort by Hire Date in Infosys Database
Watch the entire SQL playlist here: https://www.youtube.com/playlist?list=PL_neLGJ5LPUzPIg96tf7rXb57D6-3n5Pq
In this video, you'll learn how to query a database to find employees who were hired before 2020 and sort them by their hire date. We will be using Infosys as an example to demonstrate the process. Whether you're a beginner or looking to refine your SQL skills, this tutorial will help you understand the steps and logic behind filtering and sorting employee data. Don't forget to subscribe for more SQL tutorials and tips!
Schema:
-- Create departments table
CREATE TABLE departments (
dept_id INT PRIMARY KEY,
dept_name VARCHAR(100),
location VARCHAR(100)
);
-- Create employees table
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(100),
hire_date DATE,
salary DECIMAL(10, 2),
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES departments(dept_id)
);
-- Insert data into departments table
INSERT INTO departments (dept_id, dept_name, location)
VALUES
(101, 'HR', 'New York'),
(102, 'IT', 'San Francisco'),
(103, 'Marketing', 'Los Angeles'),
(104, 'Finance', 'Chicago');
-- Insert data into employees table
INSERT INTO employees (emp_id, emp_name, hire_date, salary, dept_id)
VALUES
(1, 'Alice Johnson', '2020-01-15', 75000.00, 101),
(2, 'Bob Smith', '2019-03-22', 95000.00, 102),
(3, 'Carol White', '2021-07-09', 85000.00, 103),
(4, 'David Brown', '2018-10-25', 105000.00, 102),
(5, 'Emily Davis', '2022-05-30', 68000.00, 104);
Expected Output:
emp_name hire_date dept_name
David Brown 2018-10-25 IT
Bob Smith 2019-03-22 IT
Relevant Hashtags: #SQLTutorial #SQL #SQLQueries #LearnSQL #Infosys #SQLExample #DatabaseQuery #EmployeeData #SortByDate #SQLForBeginners #SQLFilter #SQLSorting #HireDate #EmployeeRecords #DatabaseManagement #SQLDatabase #SQLScript #TechTutorials #InfosysSQL #SQLQueryExamples #SQLTips