SQL Project: Database Management with SQL Queries
1. Retrieve All Records from a Table
Description:
This query demonstrates how to retrieve all records from a specific table. It is one of the most
fundamental queries used in SQL. The SELECT * command fetches all columns from the table,
which is useful when reviewing all available data in a table.
SQL Code:
SELECT * FROM employees;
Sample Output:
emp_id emp_name emp_age emp_salary
101 John 25 50000
102 Alice 30 55000
103 Bob 28 60000
104 Eve 35 65000
2. Retrieve Specific Columns from a Table
Description:
This query retrieves specific columns from a table. Instead of selecting all columns with *, we
specify the column names to fetch only the data we need. This improves query performance
when dealing with large datasets.
SQL Code:
SELECT emp_name, emp_salary FROM employees;
Sample Output:
emp_name emp_salary
John 50000
Alice 55000
Bob 60000
Eve 65000
3. Filter Records Using a WHERE Clause
Description:
The WHERE clause filters records based on specified conditions. It is one of the most powerful
clauses in SQL for retrieving a subset of data from a table. This query selects employees with a
salary greater than 55,000.
SQL Code:
SELECT emp_id, emp_name, emp_salary FROM employees
WHERE emp_salary > 55000;
Sample Output:
emp_id emp_name emp_salary
103 Bob 60000
104 Eve 65000
4. Updating a Record in a Table
Description:
This query demonstrates how to update specific records in a table. The UPDATE statement
modifies existing data in a table based on specified conditions. In this example, we are updating
the salary of the employee with emp_id = 101.
SQL Code:
UPDATE employees
SET emp_salary = 52000
WHERE emp_id = 101;
Sample Output:
After running the query, the updated employees table will look like this:
emp_id emp_name emp_age emp_salary
101 John 25 52000
102 Alice 30 55000
103 Bob 28 60000
104 Eve 35 65000
5. Join Two Tables
Description:
The JOIN operation is used to combine data from two or more tables based on a related column
between them. This query performs an inner join on two tables: employees and
departments. It retrieves the employee's name and their corresponding department.
SQL Code:
SELECT employees.emp_name, departments.department_name
FROM employees
INNER JOIN departments ON employees.emp_id = departments.emp_id;
Sample Output:
emp_name department_name
John HR
Alice IT
Bob Marketing
Eve Finance
Conclusion
This SQL project has provided a practical understanding of common database operations such
as data retrieval, filtering, updating, and joining tables. Through the five queries presented, I
have gained hands-on experience with fundamental SQL concepts such as the SELECT,
WHERE, UPDATE, and JOIN commands. These operations are the building blocks of working
with relational databases and are essential for tasks such as data analysis, reporting, and
application development.
The ability to filter data, retrieve specific columns, update records, and combine data from
multiple tables are vital skills for anyone working with databases. This project has enabled me to
appreciate the power of SQL in managing large datasets and extracting meaningful insights
from relational databases.
By completing this project, I now feel confident in using SQL to query and manipulate data,
making it a valuable skill for future endeavors in the field of data management, software
development, and business analytics.