Welcome to SQL Task 3 of my Elevate Labs internship! This project demonstrates basic and intermediate SQL queries, focusing on data retrieval, filtering, logical operators, and pattern matching.
The primary goal of this task is to:
- Filter Data: Use
WHEREto retrieve specific records. - Logical Operations: Combine conditions using
ANDandOR. - Pattern Matching: Search for specific text patterns using
LIKE. - Range & Set Filtering: Efficiently query data using
INandBETWEEN. - Handle Nulls: Identify missing values using
IS NULL.
To successfully run the scripts in this project, ensure you have the following:
- SQL Server: MySQL, MariaDB, or any compatible SQL engine.
- SQL Client: A command-line interface (CLI) or a graphical tool like MySQL Workbench.
The project uses a students table to demonstrate data querying techniques.
| Column Name | Data Type | Description |
|---|---|---|
🔑 id |
INT |
Primary Key, Auto-increment |
👤 name |
VARCHAR(50) |
Full name of the student |
🔢 age |
INT |
Student's age |
📧 email |
VARCHAR(100) |
Student's email address |
🏢 department |
VARCHAR(50) |
Department of the student |
Follow these steps to initialize and test the database:
- Start Server: Ensure your SQL server instance is running.
- Connect: Use your preferred SQL client to connect to the server.
- Execute Script: Open and run the
task 3.sqlfile.source path/to/task 3.sql;
- Verify: Check the output to observe the results of different SQL query operations.
The task 3.sql script includes several essential SQL operations:
SELECT * FROM students WHERE age > 20;SELECT * FROM students WHERE age > 20 AND department = 'CSE';
SELECT * FROM students WHERE department = 'IT' OR department = 'MECH';SELECT * FROM students WHERE name LIKE 'A%';
SELECT * FROM students WHERE email LIKE '%gmail%';SELECT * FROM students WHERE department IN ('CSE', 'IT');
SELECT * FROM students WHERE age BETWEEN 20 AND 22;Tip
You can execute the different SELECT queries individually to observe how the WHERE, LIKE, and logical operators filter the result set differently.