-
Notifications
You must be signed in to change notification settings - Fork 138
Added Operators in sql docs #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,330 @@ | ||||||
| --- | ||||||
| id: sql-operators | ||||||
| title: SQL Operators | ||||||
| sidebar_label: SQL Operators | ||||||
| sidebar_position: 6 | ||||||
| tags: [sql, operators, database, relational-databases, queries] | ||||||
| description: In this beginner-friendly tutorial, you will learn about SQL operators, which help you filter, compare, and manipulate data in your database queries effectively. | ||||||
| keywords: [sql, operators, sql tutorial, sql basics, database queries, relational databases, sql operators tutorial, sql for beginners, sql in 2025] | ||||||
| --- | ||||||
|
|
||||||
| ## 📙 Welcome to SQL Operators! | ||||||
|
|
||||||
| Hey there! Ready to make your SQL queries more powerful? Operators are like tools that help you compare, calculate, and filter data in your database. Think of them as the "action words" that tell SQL what to do with your data. Let's dive in with simple examples that anyone can follow! | ||||||
|
|
||||||
| ### 📘 What Are SQL Operators? | ||||||
|
|
||||||
| SQL operators are symbols or keywords that help you: | ||||||
| - Compare values (like finding students older than 18) | ||||||
| - Perform calculations (like adding prices) | ||||||
| - Filter data (like finding names that start with 'A') | ||||||
| - Combine conditions (like students who are seniors AND have good grades) | ||||||
|
|
||||||
| Imagine you have a `students` table and want to find specific information. Operators make this super easy! | ||||||
|
|
||||||
| :::tip Pro Tip | ||||||
| Operators are the building blocks of powerful SQL queries. Master them, and you'll be querying like a pro! | ||||||
| ::: | ||||||
|
|
||||||
| ### 📘 Arithmetic Operators (Math Made Simple) | ||||||
|
|
||||||
| These operators help you do math with your data: | ||||||
|
|
||||||
| - **+**: Addition | ||||||
| - **-**: Subtraction | ||||||
| - **\***: Multiplication | ||||||
| - **/**: Division | ||||||
| - **%**: Modulo (remainder after division) | ||||||
|
|
||||||
| **Example**: | ||||||
|
|
||||||
| ```sql title="Using Arithmetic Operators" | ||||||
| CREATE TABLE products ( | ||||||
| id INT, | ||||||
| price DECIMAL(10,2), | ||||||
| quantity INT | ||||||
| ); | ||||||
|
|
||||||
| INSERT INTO products VALUES (1, 15.99, 10), (2, 25.50, 5); | ||||||
|
|
||||||
| -- Calculate total value for each product | ||||||
| SELECT id, price, quantity, | ||||||
| price * quantity AS total_value, | ||||||
| price + 2.00 AS price_with_tax | ||||||
| FROM products; | ||||||
| ``` | ||||||
|
|
||||||
| **Output:** | ||||||
| | id | price | quantity | total_value | price_with_tax | | ||||||
| |----|-------|----------|-------------|----------------| | ||||||
| | 1 | 15.99 | 10 | 159.90 | 17.99 | | ||||||
| | 2 | 25.50 | 5 | 127.50 | 27.50 | | ||||||
|
|
||||||
| :::warning What NOT to Do | ||||||
| Don't divide by zero—it will cause an error! Always check your divisor values. | ||||||
| ::: | ||||||
|
|
||||||
| ### 🔍 Comparison Operators (Finding What You Need) | ||||||
|
|
||||||
| These operators help you compare values and find specific data: | ||||||
|
|
||||||
| - **=**: Equal to | ||||||
| - **!=** or **<>**: Not equal to | ||||||
| - **>**: Greater than | ||||||
| - **<**: Less than | ||||||
| - **>=**: Greater than or equal to | ||||||
| - **<=**: Less than or equal to | ||||||
|
|
||||||
| **Example**: | ||||||
|
|
||||||
| ```sql title="Using Comparison Operators" | ||||||
| CREATE TABLE students ( | ||||||
| id INT, | ||||||
| name VARCHAR(50), | ||||||
| age INT, | ||||||
| grade CHAR(1) | ||||||
| ); | ||||||
|
|
||||||
| INSERT INTO students VALUES | ||||||
| (1, 'Alice', 20, 'A'), | ||||||
| (2, 'Bob', 18, 'B'), | ||||||
| (3, 'Charlie', 22, 'A'); | ||||||
|
|
||||||
| -- Find students older than 18 | ||||||
| SELECT * FROM students WHERE age > 18; | ||||||
|
|
||||||
| -- Find students with grade A | ||||||
| SELECT * FROM students WHERE grade = 'A'; | ||||||
| ``` | ||||||
|
|
||||||
| **Output:** | ||||||
|
|
||||||
| **Students older than 18:** | ||||||
| | id | name | age | grade | | ||||||
| |----|---------|-----|-------| | ||||||
| | 1 | Alice | 20 | A | | ||||||
| | 3 | Charlie | 22 | A | | ||||||
|
|
||||||
| **Students with grade A:** | ||||||
| | id | name | age | grade | | ||||||
| |----|---------|-----|-------| | ||||||
| | 1 | Alice | 20 | A | | ||||||
| | 3 | Charlie | 22 | A | | ||||||
|
|
||||||
| :::warning What NOT to Do | ||||||
| Don't use = for NULL values—use IS NULL or IS NOT NULL instead! | ||||||
| ::: | ||||||
|
|
||||||
| ### 🔄 Logical Operators (Combining Conditions) | ||||||
|
|
||||||
| These operators help you combine multiple conditions: | ||||||
|
|
||||||
| - **AND**: Both conditions must be true | ||||||
| - **OR**: At least one condition must be true | ||||||
| - **NOT**: Opposite of the condition | ||||||
| - **IN**: Value matches any in a list | ||||||
| - **BETWEEN**: Value is within a range | ||||||
|
|
||||||
| **Example**: | ||||||
|
|
||||||
| ```sql title="Using Logical Operators" | ||||||
| -- Find students who are older than 18 AND have grade A | ||||||
| SELECT * FROM students | ||||||
| WHERE age > 18 AND grade = 'A'; | ||||||
|
|
||||||
| -- Find students who are either 18 OR 22 years old | ||||||
| SELECT * FROM students | ||||||
| WHERE age = 18 OR age = 22; | ||||||
|
|
||||||
| -- Find students whose age is between 19 and 21 | ||||||
| SELECT * FROM students | ||||||
| WHERE age BETWEEN 19 AND 21; | ||||||
|
|
||||||
| -- Find students with grades A or B | ||||||
| SELECT * FROM students | ||||||
| WHERE grade IN ('A', 'B'); | ||||||
| ``` | ||||||
|
|
||||||
| **Output:** | ||||||
|
|
||||||
| **Age > 18 AND grade = 'A':** | ||||||
|
||||||
| **Age > 18 AND grade = 'A':** | |
| **Age > 18 AND grade = 'A':** |
Copilot
AI
Aug 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTML entities should be replaced with actual symbols. Use >, <, >=, <= instead of their HTML entity equivalents for better readability.
| - **Comparison Operators**: =, !=, >, <, >=, <= for filtering | |
| - **Comparison Operators**: =, !=, >, <, >=, <= for filtering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTML entities are being used instead of actual symbols. Replace
<with<,>with>, and<>with<>for better readability in markdown.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant be done , will getting MDX error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. this will work