Skip to content

Commit ced19fd

Browse files
authored
Merge pull request #405 from Adez017/frontend
Update the-inequality-operator.md
2 parents 6340c33 + 3652375 commit ced19fd

File tree

1 file changed

+68
-54
lines changed

1 file changed

+68
-54
lines changed

docs/sql/SQL-basics/the-inequality-operator.md

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ id: the-inequality-operator
33
title: The Inequality Operator
44
sidebar_label: The Inequality Operator
55
sidebar_position: 4
6-
tags: [html, web-development, document-structure]
7-
description: In this tutorial, you will learn about the structure of an HTML document and how to create a basic HTML document.
6+
tags: [sql, database, queries, operators]
7+
description: In this tutorial, you will learn about the inequality operator and comparison operators in SQL to filter data effectively.
88
---
99

1010

1111
# 📗 The Inequality Operator
12-
To check if a coloumns value is not equal to another we use the inequality operator.
12+
The inequality operator (`<>` or `!=`) helps you find records that **don't match** a specific value. Think of it as asking "show me everything except this!"
1313

14-
For example, consider a table named `Friends`. Below is how a simple table might look:
14+
Let's start with a simple example. Imagine you have a `students` table and want to find all students who are NOT in their first year:
1515

1616

1717

1818
:::info
1919
<Tabs>
2020
<TabItem value="SQL Table" label="SQL Table">
21-
```sql title="Friends"
21+
```sql title="Students"
2222

2323
| name | year | major |
2424
|-------------|------|---------|
@@ -30,7 +30,7 @@ For example, consider a table named `Friends`. Below is how a simple table might
3030

3131
<TabItem value="SQL Code" label="SQL Code">
3232

33-
```sql title="Creating SQL Tables & db. "
33+
```sql title="Finding students not in year 1"
3434
SELECT *
3535
FROM students
3636
WHERE year <> 1;
@@ -39,7 +39,7 @@ WHERE year <> 1;
3939

4040
</TabItem>
4141

42-
<TabItem value="how-git-works" label="Output ">
42+
<TabItem value="Output" label="Output">
4343
| name | year | major |
4444
| -------- | ---- | ------- |
4545
| Lin Wong | 3 | Biology |
@@ -50,19 +50,19 @@ WHERE year <> 1;
5050

5151

5252

53-
### 📘 Practise Example
53+
### 📘 Let's Practice Together
5454

55-
> To query data from a table, use the FROM clause followed by the table's name.
55+
> Here's another way to look at it: the FROM clause tells SQL which table to look in, and WHERE tells it what to filter.
5656
5757
58-
For example, consider a table named `Friends`. Below is how a simple table might look:
58+
For example, consider a table named `students`. Let's see the same example again to reinforce the concept:
5959

6060

6161

6262
:::info
6363
<Tabs>
6464
<TabItem value="SQL Table" label="SQL Table">
65-
```sql title="Friends"
65+
```sql title="Students"
6666
| name | year | major |
6767
|-------------|------|---------|
6868
| Ava Smith | 1 | Biology |
@@ -73,15 +73,15 @@ For example, consider a table named `Friends`. Below is how a simple table might
7373

7474
<TabItem value="SQL Code" label="SQL Code">
7575

76-
```sql title="Creating SQL Tables. "
76+
```sql title="Selecting non-first-year students"
7777
SELECT *
7878
FROM students
7979
WHERE year <> 1;
8080
```
8181

8282
</TabItem>
8383

84-
<TabItem value="how-git-works" label="Output">
84+
<TabItem value="Output" label="Output">
8585
| name | year | major |
8686
|----------|------|---------|
8787
| Lin Wong | 3 | Biology |
@@ -93,25 +93,33 @@ WHERE year <> 1;
9393

9494

9595

96-
:::tip
97-
The Inequality sign is useful when we want to get all items that dont satisfy a criterion.
98-
it checks the value are not equal.
99-
It can apply to all types of numbers.
96+
:::tip 💡 Quick Tip
97+
The inequality operator is your "everything except" tool! It's perfect when you want to exclude specific values from your results.
10098
101-
By following these best practices,
99+
**What it works with:**
100+
- Numbers: `age <> 25` (everyone except 25-year-olds)
101+
- Text: `major <> 'Biology'` (all majors except Biology)
102+
- Dates: `signup_date <> '2024-01-01'` (all dates except New Year's Day)
103+
104+
Pro tip: Use this when you know what you DON'T want in your results!
102105
:::
103106
104-
### 🔄 Comparison Operator.
107+
### 🔄 More Powerful Comparisons
108+
109+
**The Problem:** Sometimes you need more than just "equal" or "not equal."
110+
111+
**Real-world scenario:** You're analyzing air quality data and want to find cities with low pollution levels (under 100 on the pollution index).
105112

106-
> Sometimes, comparison with = and are not felxible enoguh like when filtering by price of a grocery itesm
107-
> We can use conditions to select items having a property les s than a threshold value like chocolate items with a price less than 2$
108-
> We can also use the numeric properties , it dont need to put in the quotes.
109-
> the = sign check if the two values are equal.
110-
We want to code a condition to select records from the pollution table where the pollution_index is less than 100.
113+
> **Good to know:**
114+
> - Numbers don't need quotes: `pollution_index < 100` ✅
115+
> - Text needs quotes: `city = 'Tokyo'` ✅
116+
> - The `<` symbol means "less than" - just like in math!
117+
118+
Here's how to find cities with clean air (pollution index under 100):
111119
:::info
112120
<Tabs>
113121
<TabItem value="SQL Table" label="SQL Table">
114-
```sql title="friends"
122+
```sql title="Pollution"
115123
| city | pollution_index |
116124
|----------|-----------------|
117125
| Delhi | 168 |
@@ -123,15 +131,15 @@ We want to code a condition to select records from the pollution table where the
123131

124132
<TabItem value="SQL Code" label="SQL Code">
125133

126-
```sql title="Creating SQL Tables. "
134+
```sql title="Finding cities with low pollution"
127135
SELECT *
128136
FROM pollution
129137
WHERE pollution_index < 100;
130138
```
131139

132140
</TabItem>
133141

134-
<TabItem value="how-git-works" label="Output">
142+
<TabItem value="Output" label="Output">
135143
| city | pollution_index |
136144
|----------|-----------------|
137145
| Shanghai | 74 |
@@ -143,15 +151,17 @@ WHERE pollution_index < 100;
143151

144152
:::
145153

146-
## 🧹 Selecting Unique Values with numeric
154+
## 🧹 Including the Boundary Value
155+
156+
**What if we want cities with "acceptable" pollution levels?** Let's say anything 122 or below is acceptable.
147157
148-
We want to code a condition to select records from the pollution table where the pollution_index is less than or equal to 122.
158+
The `<=` operator means "less than or equal to" - it includes the exact value too!
149159
150160
151161
:::info
152162
<Tabs>
153163
<TabItem value="SQL Table" label="SQL Table">
154-
```sql title="Subscribers"
164+
```sql title="Pollution"
155165
| city | pollution_index |
156166
|----------|-----------------|
157167
| Delhi | 168 |
@@ -163,15 +173,15 @@ We want to code a condition to select records from the pollution table where the
163173
164174
<TabItem value="SQL Code" label="SQL Code">
165175
166-
```sql title="Creating SQL Tables. "
176+
```sql title="Finding cities with moderate pollution"
167177
SELECT *
168178
FROM pollution
169179
WHERE pollution_index <= 122;
170180
```
171181
172182
</TabItem>
173183
174-
<TabItem value="how-git-works" label="Output">
184+
<TabItem value="Output" label="Output">
175185
| city | pollution_index |
176186
|----------|-----------------|
177187
| Milano | 122 |
@@ -185,17 +195,19 @@ WHERE pollution_index <= 122;
185195
186196
:::
187197
188-
## 🧹 Filtering coloumns
198+
## 🎯 Getting Only What You Need
199+
200+
**Smart tip:** You don't always need all the data! Sometimes you only want specific columns to make your results cleaner and easier to read.
189201

190-
When using contions we dont have to select all coloumns with *, we can select only a couple like name and year.
191-
> We dont have to select all colouns when filtering.
202+
**Example:** Instead of seeing all student info, maybe you just want names and years.
203+
> **Memory trick:** Think of `SELECT *` as "give me everything" and `SELECT name, year` as "just give me the basics"
192204

193205
---
194206

195207
:::info
196208
<Tabs>
197209
<TabItem value="SQL Table" label="SQL Table">
198-
```sql title="Subscribers"
210+
```sql title="Students"
199211
| name | year | major |
200212
|-------------|------|---------|
201213
| Ava Smith | 1 | Biology |
@@ -206,19 +218,19 @@ When using contions we dont have to select all coloumns with *, we can select on
206218

207219
<TabItem value="SQL Code" label="SQL Code">
208220

209-
```sql title="Creating SQL Tables. "
210-
SELECT *
221+
```sql title="Just names and years of first-year students"
222+
SELECT name, year
211223
FROM students
212224
WHERE year = 1;
213225
```
214226

215227
</TabItem>
216228

217-
<TabItem value="how-git-works" label="Output">
218-
| name | year | major |
219-
| ----------- | ---- | ------- |
220-
| Ava Smith | 1 | Biology |
221-
| Luis Garcia | 1 | Physics |
229+
<TabItem value="Output" label="Output">
230+
| name | year |
231+
| ----------- | ---- |
232+
| Ava Smith | 1 |
233+
| Luis Garcia | 1 |
222234

223235

224236

@@ -229,20 +241,22 @@ WHERE year = 1;
229241
:::
230242

231243

232-
## ✅ What You have Learned
244+
## 🎉 What You've Mastered
245+
246+
Great job! You've learned the essential skills for smart data filtering:
233247
234-
This module covers four essential topics in data selection:
248+
**🚫 The "Not Equal" Expert**
249+
You can now use `<>` and `!=` to exclude specific values and find everything except what you don't want.
235250

236-
- **Rows and Columns**
237-
Learn how to access specific rows and columns in a dataset or table, the building blocks of any query.
251+
**📊 The Comparison Pro**
252+
You've mastered `<`, `>`, `<=`, and `>=` for finding records above, below, or within specific ranges.
238253
239-
- **Select Data**
240-
Understand the basic `SELECT` statement to retrieve data from a database.
254+
**🎯 The Precision Selector**
255+
You know how to pick just the columns you need instead of grabbing everything with `*`.
241256
242-
- **Select Multiple Columns**
243-
Retrieve more than one column at a time in your queries to get the information you need all at once.
257+
**🔍 The Smart Filterer**
258+
You can combine `WHERE` clauses with any operator to create laser-focused queries that find exactly what you're looking for.
244259

245-
- **Select Distinct Values**
246-
Use `DISTINCT` to eliminate duplicate records and identify unique entries within your dataset.
260+
**Next up:** Try combining these operators with `AND` and `OR` to create even more powerful searches!
247261

248-
---
262+
---

0 commit comments

Comments
 (0)