Write a query to fetch all records from a table named employees.
Step 1: Create the Table
First, we create a dummy table employees
with common columns like:
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10,2),
hire_date DATE
);
Step 2: Insert Dummy Data
Here’s some sample data you can insert into the employees
table:
INSERT INTO employees (id, name, department, salary, hire_date) VALUES
(1, 'John Smith', 'HR', 50000.00, '2020-01-15'),
(2, 'Alice Johnson', 'Engineering', 75000.00, '2019-03-22'),
(3, 'Bob Lee', 'Sales', 62000.00, '2021-07-10'),
(4, 'Mary Jane', 'Engineering', 80000.00, '2018-11-05'),
(5, 'Tom Hardy', 'Marketing', 55000.00, '2022-06-01');
Step 3: Query to Fetch All Records
Now we write a simple SQL query to fetch all records from the table:
SELECT * FROM employees;
Step 4: Output (Result Set)
Here is what the output would look like when you run the above query:
id | name | department | salary | hire_date |
---|---|---|---|---|
1 | John Smith | HR | 50000.00 | 2020-01-15 |
2 | Alice Johnson | Engineering | 75000.00 | 2019-03-22 |
3 | Bob Lee | Sales | 62000.00 | 2021-07-10 |
4 | Mary Jane | Engineering | 80000.00 | 2018-11-05 |
5 | Tom Hardy | Marketing | 55000.00 | 2022-06-01 |
Summary
- The query
SELECT * FROM employees;
fetches all columns and rows from theemployees
table. - This is useful for viewing entire data but not recommended in production if the table has many columns or sensitive data—better to specify only required columns like:
SELECT id, name, department FROM employees;
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.