Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
150 views3 pages

SQL WHERE Clause Practice Guide

The document provides a practice sheet for SQL WHERE clause queries, including table creation and sample data insertion for a 'students' table. It contains various SQL queries to filter students based on different criteria such as city, gender, age, and marks. The queries are categorized into basic and intermediate levels, demonstrating the use of different SQL operators and conditions.

Uploaded by

nikita.kirar04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views3 pages

SQL WHERE Clause Practice Guide

The document provides a practice sheet for SQL WHERE clause queries, including table creation and sample data insertion for a 'students' table. It contains various SQL queries to filter students based on different criteria such as city, gender, age, and marks. The queries are categorized into basic and intermediate levels, demonstrating the use of different SQL operators and conditions.

Uploaded by

nikita.kirar04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL WHERE Clause Practice Sheet

1. Table Creation Query

CREATE TABLE students (

id INT PRIMARY KEY,

name VARCHAR(50),

age INT,

gender VARCHAR(10),

department VARCHAR(50),

marks INT,

city VARCHAR(50)

);

2. Insert Sample Data

INSERT INTO students (id, name, age, gender, department, marks, city) VALUES

(1, 'Pooja', 21, 'Female', 'Computer Science', 85, 'Bhopal'),

(2, 'Aman', 22, 'Male', 'Mechanical', 74, 'Indore'),

(3, 'Riya', 20, 'Female', 'Electronics', 91, 'Delhi'),

(4, 'Raj', 23, 'Male', 'Computer Science', 65, 'Mumbai'),

(5, 'Simran', 21, 'Female', 'Computer Science', 89, 'Bhopal'),

(6, 'Anuj', 22, 'Male', 'Civil', 55, 'Pune'),

(7, 'Sonal', 20, 'Female', 'Electronics', 92, 'Delhi'),

(8, 'Karan', 24, 'Male', 'Mechanical', 78, 'Chennai'),

(9, 'Neha', 21, 'Female', 'Civil', 62, 'Kolkata'),

(10, 'Yash', 23, 'Male', 'Computer Science', 95, 'Bangalore');

3. WHERE Clause Queries - Basic Level

1. Get all students from Bhopal:

SELECT * FROM students WHERE city = 'Bhopal';

2. Get all female students:


SQL WHERE Clause Practice Sheet

SELECT * FROM students WHERE gender = 'Female';

3. Get students with marks greater than 80:

SELECT * FROM students WHERE marks > 80;

4. Get students older than 21 years:

SELECT * FROM students WHERE age > 21;

5. Get all male students from Indore:

SELECT * FROM students WHERE gender = 'Male' AND city = 'Indore';

6. Get students from Computer Science department:

SELECT * FROM students WHERE department = 'Computer Science';

7. Get students with marks between 70 and 90:

SELECT * FROM students WHERE marks BETWEEN 70 AND 90;

8. Get students with names starting with 'S':

SELECT * FROM students WHERE name LIKE 'S%';

9. Get students whose city is not Delhi:

SELECT * FROM students WHERE city <> 'Delhi';

10. Get students whose name contains 'ya':

SELECT * FROM students WHERE name LIKE '%ya%';

4. WHERE Clause Queries - Intermediate Level

11. Students from Computer Science or Electronics:

SELECT * FROM students WHERE department IN ('Computer Science', 'Electronics');


SQL WHERE Clause Practice Sheet

12. Students not from Civil department:

SELECT * FROM students WHERE department NOT IN ('Civil');

13. Students with marks less than 60:

SELECT * FROM students WHERE marks < 60;

14. Age = 21 and marks > 80:

SELECT * FROM students WHERE age = 21 AND marks > 80;

15. Name ends with 'a':

SELECT * FROM students WHERE name LIKE '%a';

16. Not female:

SELECT * FROM students WHERE gender <> 'Female';

17. From Delhi or Mumbai:

SELECT * FROM students WHERE city IN ('Delhi', 'Mumbai');

18. Marks 85 or 95:

SELECT * FROM students WHERE marks IN (85, 95);

19. Younger than 22 and from Bhopal:

SELECT * FROM students WHERE age < 22 AND city = 'Bhopal';

20. All students except from Bangalore:

SELECT * FROM students WHERE city != 'Bangalore';

You might also like