fundamentals/database/notes/05-sql-primer-worksheet.md

192 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2022-07-18 00:24:02 +01:00
# Queries
## Insert queries
2022-07-18 21:56:40 +05:30
1. Insert a row with your name and all the other fields in **students** table
2022-07-18 00:24:02 +01:00
```sql
```
2022-07-21 00:20:43 +05:30
2. Insert a row with just mandatory fields in **students** table
2022-07-18 00:24:02 +01:00
```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
```
2022-07-21 00:20:43 +05:30
15. Get all students without the first name `John` or first name `Mycroft`
2022-07-18 00:24:02 +01:00
```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
```
2022-07-21 00:20:43 +05:30
20. Get all students from Jhansi and London
2022-07-18 00:24:02 +01:00
```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
```
2022-07-21 00:20:43 +05:30
2. Delete multiple rows
2022-07-18 00:24:02 +01:00
```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
2022-07-18 21:56:40 +05:30
```