Welcome to the SQL Queries Collection repository! π This repository contains a collection of SQL queries for a variety of common operations and tasks, such as SELECT
, INSERT
, UPDATE
, DELETE
, and JOIN
operations, which are fundamental to working with SQL databases. The goal of this project is to provide practical SQL code examples for easy learning and reference. π
π½ Click to expand Table of Contents
This project is designed to help developers and learners with SQL queries. It contains organized SQL query files that can be used in your projects or as learning examples. Whether you're just starting with SQL or you need a quick reference, you'll find useful query examples here. The repository is open for contribution, so feel free to add your own queries or improvements. π
This file contains examples of various SELECT
statements that are fundamental for retrieving data from a database. π
- Basic SELECT: Retrieve all records from a table.
- WHERE Clause: Filter data based on conditions.
- AND/OR Conditions: Combine multiple conditions.
- LIKE Pattern Matching: Search for records with specific patterns.
- ORDER BY: Sort the results.
- DISTINCT: Retrieve unique values.
- JOIN Queries: Combine data from multiple tables.
Example:
SELECT * FROM employees;
You can find more details in the SELECT-Queries.sql file. π
This file demonstrates different types of JOIN
operations for combining data from multiple tables. π
- INNER JOIN: Returns rows when there is a match in both tables.
- LEFT JOIN: Returns all rows from the left table and matched rows from the right table.
- RIGHT JOIN: Returns all rows from the right table and matched rows from the left table.
- FULL OUTER JOIN: Returns all rows when there is a match in one of the tables.
- SELF JOIN: Join a table with itself.
Example:
SELECT e.first_name, e.last_name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;
For more details, refer to the JOIN-Queries.sql file. π
This file covers examples of INSERT
queries for adding data into a table. β¨
- Single INSERT: Add a single record to a table.
- Multiple INSERT: Add multiple records at once.
- INSERT from SELECT: Insert data from another table.
Example:
INSERT INTO employees (first_name, last_name, department, salary)
VALUES ('John', 'Doe', 'IT', 60000);
For more information, refer to the INSERT-Queries.sql file. π
This file demonstrates the use of UPDATE
queries to modify data in an existing table. π
- Basic UPDATE: Update a single record.
- Multiple Record UPDATE: Modify data for multiple records.
- UPDATE with JOIN: Modify data based on a JOIN condition.
- Conditional UPDATE: Update data conditionally using
CASE
.
Example:
UPDATE employees
SET salary = 65000
WHERE first_name = 'John' AND last_name = 'Doe';
Check the UPDATE-Queries.sql file for further examples. π
This file includes various DELETE
queries for removing data from a table. ποΈ
- Basic DELETE: Remove a specific record.
- DELETE Multiple Records: Delete records based on a condition.
- DELETE with JOIN: Delete records based on a JOIN condition.
- TRUNCATE: Remove all records from a table.
Example:
DELETE FROM employees
WHERE first_name = 'John' AND last_name = 'Doe';
More examples can be found in the DELETE-Queries.sql file. ποΈ
We welcome contributions from the community! π€ If you'd like to contribute, please follow these steps:
- Fork the repository π΄.
- Create a new branch (
git checkout -b feature-name
) π±. - Make your changes β¨.
- Commit your changes (
git commit -am 'Add new query'
) π. - Push to your branch (
git push origin feature-name
) π. - Open a pull request π.
Please ensure that your contributions are in the form of SQL code examples with proper comments explaining the query logic. π¬
This project is licensed under the MIT License - see the LICENSE file for details. π
- Repository URL π
- MIT License π
- SQL Documentation π
- SQL Cheat Sheet π
Feel free to use, modify, and contribute to this collection of SQL queries. Happy querying! π