Skip to content

Commit cb8d5a0

Browse files
committed
Edited the filtering data page
1 parent 758530d commit cb8d5a0

File tree

1 file changed

+87
-97
lines changed

1 file changed

+87
-97
lines changed

docs/sql/SQL-basics/filtering-data.md

Lines changed: 87 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ id: filtering-data
33
title: SQL Filtering Data
44
sidebar_label: SQL Filtering Data
55
sidebar_position: 3
6-
tags: [html, web-development, attributes, values]
7-
description: In this tutorial, you will learn about HTML attributes and values. HTML attributes provide additional information about elements, and values define the specific settings or properties of the attributes.
8-
keywords: [html, web development, attributes, values, html attributes, html values, html tutorial, html basics, web design, web pages, websites, html structure, html attributes tutorial, html values tutorial, html in 2024]
6+
tags: [html, web-development, attributes, values, SQL]
7+
description: This document is a tutorial on SQL data filtering techniques, designed for beginners learning database querying. It covers the fundamental concepts and practical applications of retrieving specific data from database tables.
8+
keywords: [sql filtering, sql where clause, sql distinct, sql select statement, sql tutorial, sql basics, sql data filtering, sql query tutorial, sql database filtering, sql conditional queries, sql duplicate removal, sql unique values, sql filtering examples, sql beginner tutorial, sql data retrieval, sql filtering techniques, sql where examples, sql distinct tutorial, sql filtering rows, sql column selection, sql 2024]
99
---
1010

11-
## 📙 Using Conditions
11+
## 📙 Selecting Data
1212

1313
Welcome to the **Selecting Data** module! This foundational learning path is designed to help you master the basics of querying data, particularly focusing on how to retrieve specific information from databases effectively.
1414

15-
### 📘 Using Coditions
15+
### 📘 Using Conditions with the WHERE Clause
1616

1717
In this tutorial, you'll learn how to interpret and use rows in a database table. Tables are essential to storing structured data, and each **row** in a table represents a unique **item or record**.
18-
> The first step in filtering is selecting the Items
19-
> We use WHERE keyword to filter the data., we also apply the condition over there.
20-
> We filter the table items we slect to get only items that satisy certain conditions.
21-
> The condition we want our items to fulfil comes after the where keyword
18+
> The first step in filtering is selecting the items.
19+
> We use **WHERE** keyword to filter the data by applying conditions.
20+
> We filter the table items, we select to get only items that satisfy certain conditions.
21+
> The condition we want our items to fulfill comes after the where keyword
2222
2323

24-
For example, consider a table named `Friends`. Below is how a simple table might look:
24+
For example, consider a table named `Students`. Below is how a simple table might look:
2525

2626

2727

28-
:::info
28+
:::info
2929
<Tabs>
3030
<TabItem value="SQL Table" label="SQL Table">
31-
```sql title="Friends"
31+
```sql title="Students"
3232
| name | year | major |
3333
|-------------|------|---------|
3434
| Ava Smith | 1 | Biology |
@@ -37,42 +37,41 @@ For example, consider a table named `Friends`. Below is how a simple table might
3737
```
3838
</TabItem>
3939

40-
<TabItem value="SQL Code" label="SQL Code">
40+
<TabItem value="SQL Code" label="SQL Code">
4141

42-
```sql title="Creating SQL Tables & db. "
43-
SELECT *
44-
FROM students
45-
WHERE major = 'Biology';
42+
```sql title="Select command with a condition"
43+
SELECT *
44+
FROM Students
45+
WHERE major = 'Biology';
46+
```
4647

47-
```
48-
49-
</TabItem>
48+
</TabItem>
5049

51-
<TabItem value="how-git-works" label="Output ">
50+
<TabItem value="Students" label="Output ">
5251
| name | year | major |
5352
|-----------|------|---------|
5453
| Ava Smith | 1 | Biology |
5554
| Lin Wong | 3 | Biology |
5655
</TabItem>
5756
</Tabs>
57+
:::
5858

5959

6060

6161

62+
### 📘 Practice Example
6263

63-
### 📘 Practise Example
64-
65-
> To query data from a table, use the FROM clause followed by the table's name.
64+
> To query data from a table, use the FROM clause followed by the table&apos;s name and then the WHERE clause to specify the conditions for the data you want to retrieve.
6665
6766

68-
For example, consider a table named `Friends`. Below is how a simple table might look:
67+
For example, consider a table named `Students`. Below is how a simple table might look:
6968

7069

7170

72-
:::info
71+
:::info
7372
<Tabs>
7473
<TabItem value="SQL Table" label="SQL Table">
75-
```sql title="Friends"
74+
```sql title="Students"
7675
| name | email | type |
7776
|------|-------------------|-------|
7877
| Sam | sam17@mail.com | free |
@@ -82,52 +81,46 @@ For example, consider a table named `Friends`. Below is how a simple table might
8281
```
8382
</TabItem>
8483

85-
<TabItem value="SQL Code" label="SQL Code">
84+
<TabItem value="SQL Code" label="SQL Code">
8685

87-
```sql title="Creating SQL Tables. "
86+
```sql title="Data from the table where type is pro"
8887
SELECT *
89-
FROM friends
88+
FROM Students
9089
WHERE type = 'pro';
91-
```
92-
93-
</TabItem>
90+
```
91+
</TabItem>
9492

95-
<TabItem value="how-git-works" label="Output">
93+
<TabItem value="Students table" label="Output">
9694
| name | email | type |
9795
|-------|---------------|------|
9896
| Re my | [email protected] | pro |
9997
| Kim | [email protected] | pro |
100-
</TabItem>
98+
</TabItem>
10199
</Tabs>
102-
103-
104100
:::
105101

106102

107103

108104
:::tip
109-
When requesting data with SQL staments like SELECT, we say that we are making a query.
110-
From helps in select the name col from
111-
While not necessary but its a good practice to finish the sql queries with;
112-
113-
114-
By following these best practices,
105+
When requesting data with SQL statements like SELECT, we say that we are making a query.
106+
From helps in selecting columns from the table we are working on.
107+
While not necessary but it&apos;s a good practice to finish the sql queries with ";"
115108
:::
116109

117110
### 🔄 Checking Equality
118111

119112
> We use the = operator to check if the two values are equal.
120113
121-
> The values like text values are writtern between single quotes.
114+
> The values like text values are written between single quotes.
122115
123-
> We can also use the numeric properties , it dont need to put in the quotes.
116+
> We can also use numeric values, we don&apos;t need to put them in the quotes.
124117
125-
> the = sign check if the two values are equal.
118+
> the = sign check if the two values are equal.
126119
127-
:::info
120+
:::info
128121
<Tabs>
129122
<TabItem value="SQL Table" label="SQL Table">
130-
```sql title="friends"
123+
```sql title="Students"
131124
| name | year | major |
132125
|-------------|------|---------|
133126
| Ava Smith | 1 | Biology |
@@ -136,80 +129,77 @@ By following these best practices,
136129
```
137130
</TabItem>
138131

139-
<TabItem value="SQL Code" label="SQL Code">
132+
<TabItem value="SQL Code" label="SQL Code">
140133

141-
```sql title="Creating SQL Tables. "
134+
```sql title="Selecting data WHERE major = Biology"
142135
SELECT *
143-
FROM students
136+
FROM Students
144137
WHERE major = 'Biology';
145-
```
146-
147-
</TabItem>
138+
```
139+
</TabItem>
148140

149-
<TabItem value="how-git-works" label="Output">
141+
<TabItem value="Students table" label="Output">
150142
| name | year | major |
151143
| --------- | ---- | ------- |
152144
| Ava Smith | 1 | Biology |
153145
| Lin Wong | 3 | Biology |
154146

155-
</TabItem>
147+
</TabItem>
156148
</Tabs>
157-
158-
159149
:::
160150

161-
## 🧹 Selecting Unique Values with numeric
151+
### 🧹 Selecting Unique Values with DISTINCT
162152

163-
We can also use `=` with numeric properties, like selecting only students that have the year value `1`.
153+
DISTINCT removes duplicate rows from the result set, returning only unique values or combinations.
154+
155+
> In the table below, duplicate rows (if any student appears multiple times with identical name, year, and major) will be removed.
164156
165157
---
166158

167-
:::info
159+
:::info
168160
<Tabs>
169161
<TabItem value="SQL Table" label="SQL Table">
170-
```sql title="Subscribers"
162+
```sql title="Students"
171163
| name | year | major |
172164
|-------------|------|---------|
173165
| Ava Smith | 1 | Biology |
174166
| Luis Garcia | 1 | Physics |
175167
| Lin Wong | 3 | Biology |
168+
| Ava Smith | 1 | Biology |
176169
```
177170
</TabItem>
178171

179172
<TabItem value="SQL Code" label="SQL Code">
180173

181-
```sql title="Creating SQL Tables. "
182-
SELECT *
183-
FROM students
184-
WHERE year = 1;
185-
```
174+
```sql title="Selecting unique values."
175+
SELECT DISTINCT name, year, major
176+
FROM Students;
177+
```
186178

187-
</TabItem>
179+
</TabItem>
188180

189-
<TabItem value="how-git-works" label="Output">
181+
<TabItem value="Students table" label="Output">
190182
| name | year | major |
191183
| ----------- | ---- | ------- |
192184
| Ava Smith | 1 | Biology |
193185
| Luis Garcia | 1 | Physics |
194-
195-
196-
</TabItem>
186+
| Lin Wong | 3 | Biology |
187+
</TabItem>
197188
</Tabs>
198189

199-
200190
:::
201191

202-
## 🧹 Filtering coloumns
192+
### 🧹 Filtering columns
203193

204-
When using contions we dont have to select all coloumns with *, we can select only a couple like name and year.
205-
> We dont have to select all colouns when filtering.
194+
When using conditions we don&apos;t have to select all columns with *, we can select only a couple like name and year.
195+
> We don&apos;t have to select all columns when filtering.
206196
207197
---
208198

209-
:::info
199+
:::info
210200
<Tabs>
211201
<TabItem value="SQL Table" label="SQL Table">
212-
```sql title="Subscribers"
202+
```sql title="Students"
213203
| name | year | major |
214204
|-------------|------|---------|
215205
| Ava Smith | 1 | Biology |
@@ -220,43 +210,43 @@ When using contions we dont have to select all coloumns with *, we can select on
220210

221211
<TabItem value="SQL Code" label="SQL Code">
222212

223-
```sql title="Creating SQL Tables. "
224-
SELECT *
225-
FROM students
226-
WHERE year = 1;
227-
```
213+
```sql title="Selecting name and year columns."
214+
SELECT name, year
215+
FROM Students;
216+
```
228217

229-
</TabItem>
218+
</TabItem>
230219

231-
<TabItem value="how-git-works" label="Output">
232-
| name | year | major |
233-
| ----------- | ---- | ------- |
234-
| Ava Smith | 1 | Biology |
235-
| Luis Garcia | 1 | Physics |
236-
237-
220+
<TabItem value="Table with selected columns" label="Output">
221+
| name | year |
222+
| ----------- | ---- |
223+
| Ava Smith | 1 |
224+
| Luis Garcia | 1 |
225+
| Lin Wong | 3 |
238226

239-
</TabItem>
227+
</TabItem>
240228
</Tabs>
241229

242230

243231
:::
244232

245233

246-
## ✅ What You have Learned
234+
## ✅ What You have Learnt
247235

248236
This module covers four essential topics in data selection:
249237

250238
- **Rows and Columns**
251-
Learn how to access specific rows and columns in a dataset or table, the building blocks of any query.
239+
> Learn how to access specific rows and columns in a dataset or table, the building blocks of any query.
240+
> We selected specific rows using conditions and columns using the SELECT statement.
241+
252242

253243
- **Select Data**
254-
Understand the basic `SELECT` statement to retrieve data from a database.
244+
> Understand the basic `SELECT` statement to retrieve data from a database.
255245
256246
- **Select Multiple Columns**
257-
Retrieve more than one column at a time in your queries to get the information you need all at once.
247+
> Retrieve more than one column at a time in your queries to get the information you need all at once.
258248
259249
- **Select Distinct Values**
260-
Use `DISTINCT` to eliminate duplicate records and identify unique entries within your dataset.
250+
> Use `DISTINCT` to eliminate duplicate records and identify unique entries within your dataset.
261251
262252
---

0 commit comments

Comments
 (0)