0% found this document useful (0 votes)
23 views3 pages

MySQL Queries Students Table Fully Updated

The document outlines the structure and sample data for a 'Students' table in MySQL, including various queries and their outcomes. It provides SQL commands to retrieve, update, and manipulate student records based on different criteria such as age, city, and grade. Additionally, it includes operations for counting, averaging, and deleting records, as well as inserting new student data.

Uploaded by

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

MySQL Queries Students Table Fully Updated

The document outlines the structure and sample data for a 'Students' table in MySQL, including various queries and their outcomes. It provides SQL commands to retrieve, update, and manipulate student records based on different criteria such as age, city, and grade. Additionally, it includes operations for counting, averaging, and deleting records, as well as inserting new student data.

Uploaded by

Gourav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

MySQL Queries and Outcomes for 'Students' Table

Table: Students

CREATE TABLE Students (


StudentID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Age INT,
Gender VARCHAR(10),
Grade VARCHAR(10),
City VARCHAR(50),
AdmissionDate DATE
);

Sample Data

INSERT INTO Students VALUES


(1, 'Aarav', 'Sharma', 20, 'Male', 'A', 'Mumbai', '2022-01-15'),
(2, 'Ishita', 'Verma', 22, 'Female', 'B', 'Delhi', '2021-06-10'),
(3, 'Rohan', 'Singh', 19, 'Male', 'A', 'Chennai', '2023-03-22'),
(4, 'Meera', 'Nair', 21, 'Female', 'C', 'Bangalore', '2020-09-05'),
(5, 'Ananya', 'Iyer', 20, 'Female', 'B', 'Kolkata', '2022-12-01'),
(6, 'Vihaan', 'Patel', 23, 'Male', 'C', 'Ahmedabad', '2019-11-11'),
(7, 'Priya', 'Reddy', 18, 'Female', 'A', 'Hyderabad', '2023-05-30'),
(8, 'Aditya', 'Mishra', 21, 'Male', 'B', 'Pune', '2021-01-20'),
(9, 'Riya', 'Joshi', 22, 'Female', 'A', 'Chennai', '2020-02-14'),
(10, 'Karan', 'Gupta', 20, 'Male', 'C', 'Delhi', '2022-07-19');

MySQL Queries with Outcomes


Table Data:

+-----------+-----------+----------+-----+--------+-------+-----------+---------------+
| StudentID | FirstName | LastName | Age | Gender | Grade | City | AdmissionDate |
+-----------+-----------+----------+-----+--------+-------+-----------+---------------+
|1 | Aarav | Sharma | 20 | Male | A | Mumbai | 2022-01-15 |
|2 | Ishita | Verma | 22 | Female | B | Delhi | 2021-06-10 |
|3 | Rohan | Singh | 19 | Male | A | Chennai | 2023-03-22 |
|4 | Meera | Nair | 21 | Female | C | Bangalore | 2020-09-05 |
|5 | Ananya | Iyer | 20 | Female | B | Kolkata | 2022-12-01 |
|6 | Vihaan | Patel | 23 | Male | C | Ahmedabad | 2019-11-11 |
|7 | Priya | Reddy | 18 | Female | A | Hyderabad | 2023-05-30 |
|8 | Aditya | Mishra | 21 | Male | B | Pune | 2021-01-20 |
|9 | Riya | Joshi | 22 | Female | A | Chennai | 2020-02-14 |
| 10 | Karan | Gupta | 20 | Male | C | Delhi | 2022-07-19 |
+-----------+-----------+----------+-----+--------+-------+-----------+---------------+

1. Retrieve all records from the table:


Outcome:
All 10 records will be displayed as inserted in the `Students` table.
SELECT * FROM Students;

2. Find all students aged 20:


Outcome:

(1, 'Aarav', 'Sharma', 20, 'Male', 'A', 'Mumbai', '2022-01-15'),


(5, 'Ananya', 'Iyer', 20, 'Female', 'B', 'Kolkata', '2022-12-01'),
(10, 'Karan', 'Gupta', 20, 'Male', 'C', 'Delhi', '2022-07-19')

SELECT * FROM Students WHERE Age = 20;

3. List students from Mumbai:


Outcome:
(1, 'Aarav', 'Sharma', 20, 'Male', 'A', 'Mumbai', '2022-01-15')
SELECT * FROM Students WHERE City = 'Mumbai';

4. Find students with grade 'A':


Outcome:

(7, 'Priya', 'Reddy', 18, 'Female', 'A', 'Hyderabad', '2023-05-30'),


(3, 'Rohan', 'Singh', 19, 'Male', 'A', 'Chennai', '2023-03-22'),
(1, 'Aarav', 'Sharma', 20, 'Male', 'A', 'Mumbai', '2022-01-15'),
(9, 'Riya', 'Joshi', 22, 'Female', 'A', 'Chennai', '2020-02-14')

SELECT * FROM Students WHERE Grade = 'A';

5. Count the number of male students:


SELECT COUNT(*) AS MaleCount FROM Students WHERE Gender = 'Male';

6. Get the average age of students:


SELECT AVG(Age) AS AverageAge FROM Students;

7. Find students admitted after 2021-01-01:


SELECT * FROM Students WHERE AdmissionDate > '2021-01-01';
8. Retrieve students sorted by their last name:
SELECT * FROM Students ORDER BY LastName;

9. Group students by city and count them:


SELECT City, COUNT(*) AS StudentCount FROM Students GROUP BY City;

10. Find the oldest student in the table:


SELECT * FROM Students ORDER BY Age DESC LIMIT 1;

11. List female students aged between 20 and 22:


SELECT * FROM Students WHERE Gender = 'Female' AND Age BETWEEN 20 AND 22;

12. Update the city of a specific student:


UPDATE Students SET City = 'Jaipur' WHERE StudentID = 3;

13. Delete students with grade 'C':


DELETE FROM Students WHERE Grade = 'C';

14. Add a new student record:


INSERT INTO Students VALUES (11, 'Rahul', 'Chopra', 19, 'Male', 'B', 'Lucknow', '2024-01-
15');

15. Find the total number of students:


SELECT COUNT(*) AS TotalStudents FROM Students;

16. Retrieve distinct cities in the table:


SELECT DISTINCT City FROM Students;

17. Find students with names starting with 'A':


SELECT * FROM Students WHERE FirstName LIKE 'A%';

18. Display students along with their admission year:


SELECT StudentID, FirstName, LastName, YEAR(AdmissionDate) AS AdmissionYear FROM
Students;

19. List students who are not in grade 'A':


SELECT * FROM Students WHERE Grade != 'A';

20. Get the youngest student's information:


SELECT * FROM Students ORDER BY Age ASC LIMIT 1;

You might also like