mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-09-13 18:32:21 +00:00
Fixes id.
This commit is contained in:
191
database/notes/05-sql-primer-worksheet.md
Normal file
191
database/notes/05-sql-primer-worksheet.md
Normal file
@@ -0,0 +1,191 @@
|
||||
|
||||
# Queries
|
||||
|
||||
## Insert queries
|
||||
1. Insert a row with your name and all the other fields
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
1. Insert a row with just mandatory fields
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Select Queries
|
||||
1. Get all students
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
2. Get first and last name of all students
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
3. Get first name of all students with output column name as `Student Name`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
4. Get all unique addresses of all students
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
5. Get all students with ID equal to 1
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
6. Get all students with IQ greater than 150
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
7. Get all students with IQ less than 100
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
8. Get all students with IQ greater than 100 and less than150
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
9. Get all students with IQ greater than 100 or less than 150
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
10. Get all students with first name `Tantia`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
11. Get all students with first name `Tantia` and last name `Tope`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
12. Get all students with first name `John` or first name `Mycroft`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
13. Get all students with name `John Watson` or `Mycroft Holmes`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
14. Get all students without the first name `John`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
15. Get all students without the first name `John` or last name `Mycroft`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
16. Get all students with first name starting with `T`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
17. Get all students with last name ending with `walker`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
18. Get all students with first name containing `T`
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
19. Get all students with last name in the format `___walker`
|
||||
```sql
|
||||
|
||||
```
|
||||
20. Get all students in Jhansi and London
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
21. Get all students which do not have a batch id
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
22. Get the first 5 students
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
23. Get the first 5 students sorted by IQ
|
||||
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
24. Get the first 5 students sorted by IQ in descending order
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
25. Get the first 5 students sorted by IQ in descending order and then by first name
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Update Queries
|
||||
|
||||
1. Update a row
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
2. Update a row with a condition
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
3. Update multiple columns
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
## Delete Queries
|
||||
|
||||
1. Delete a row with a condition
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
2. Delete a multiple rows
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
|
||||
## Joining Queries
|
||||
|
||||
1. Get first name and last name of all students and their batch names
|
||||
|
||||
```sql
|
||||
|
||||
```
|
||||
2. Get first name and last name of all students and their instructor names
|
||||
|
||||
```sql
|
||||
```
|
Reference in New Issue
Block a user