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 theemployeestable. - 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;
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
