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

SQL Queries With Answers

The document contains a series of SQL queries related to a student database, including selecting all students, filtering by age and grade, sorting, counting, and renaming columns. Each query is followed by its expected output, showcasing the results from the 'students' table. Key operations include retrieving specific fields, applying conditions, and aggregating data.

Uploaded by

garrysandhu55677
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)
2 views3 pages

SQL Queries With Answers

The document contains a series of SQL queries related to a student database, including selecting all students, filtering by age and grade, sorting, counting, and renaming columns. Each query is followed by its expected output, showcasing the results from the 'students' table. Key operations include retrieving specific fields, applying conditions, and aggregating data.

Uploaded by

garrysandhu55677
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

SQL QUERIES

1. Select all students


Query:

SELECT * FROM students;

Answer / Output:

Shows full student table.

2. Select student names and ages


Query:

SELECT name, age FROM students;

Answer / Output:

| name | age |
|-------|-----|
| Alice | 20 |
| Bob | 22 |
| Carol | 19 |
| David | 21 |

3. Students older than 20


Query:

SELECT * FROM students WHERE age > 20;

Answer / Output:

| id | name | age | gender | grade |


|----|------|-----|--------|-------|
| 2 | Bob | 22 | M | 92.0 |
| 4 | David| 21 | M | 85.0 |

4. Sort students by grade DESC


Query:

SELECT * FROM students ORDER BY grade DESC;

Answer / Output:
Bob (92.0), Alice (88.5), David (85.0), Carol (78.0)

5. Top 2 students
Query:

SELECT * FROM students ORDER BY grade DESC LIMIT 2;

Answer / Output:

Bob (92.0), Alice (88.5)

6. Students with grade between 80 and 90


Query:

SELECT * FROM students WHERE grade BETWEEN 80 AND 90;

Answer / Output:

Alice (88.5), David (85.0)

7. Name starts with 'A'


Query:

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

Answer / Output:

Alice

8. Total number of students


Query:

SELECT COUNT(*) FROM students;

Answer / Output:

9. Unique ages
Query:

SELECT DISTINCT age FROM students;

Answer / Output:

19, 20, 21, 22


10. Rename columns
Query:

SELECT name AS student_name, grade AS marks FROM students;

Answer / Output:

| student_name | marks |
|--------------|-------|
| Alice | 88.5 |
| Bob | 92.0 |
| Carol | 78.0 |
| David | 85.0 |

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy