From 72995d70db9f9f218ef5c79cba75fc7801f095ec Mon Sep 17 00:00:00 2001 From: Damini2004 Date: Sun, 23 Jun 2024 20:36:52 +0530 Subject: [PATCH 1/3] Commit 2 --- docs/SQL/SQL-Where-Clause.md | 62 +++++++++++++++++++++++++++++++++++ docs/SQL/image.png | Bin 0 -> 15568 bytes 2 files changed, 62 insertions(+) create mode 100644 docs/SQL/SQL-Where-Clause.md create mode 100644 docs/SQL/image.png diff --git a/docs/SQL/SQL-Where-Clause.md b/docs/SQL/SQL-Where-Clause.md new file mode 100644 index 000000000..50d99216a --- /dev/null +++ b/docs/SQL/SQL-Where-Clause.md @@ -0,0 +1,62 @@ +# Introduction to SQL WHERE Clause + +The WHERE clause in SQL is used to filter records from a result set. It specifies the conditions that must be met for the rows to be included in the result. The WHERE clause is often used in SELECT, UPDATE, DELETE, and other SQL statements to narrow down the data returned or affected. + +# Syntax +`SELECT column1, column2, ... +FROM table_name +WHERE condition;` + +# Operators Used in the Where Clause +1. `= : Equal`. +2. `> : Greater than`. +3. `< : Less than`. +4. `>= : Greater than or equal`. +5. `<= : Less than or equal`. +6. `<> : Not equal. Note: In some versions of SQL this operator may be written as !=`. +7. `BETWEEN : Between a certain range`. +8. `LIKE : Search for a pattern`. +9. `IN : To specify multiple possible values for a column`. +# Advantage of SQL WHERE Clause + +**1. Filtering Rows:** The WHERE clause evaluates each row in the table to determine if it meets the specified condition(s). Only rows that satisfy the condition are included in the result set. + +**2. Conditions:** Conditions in the WHERE clause can use comparison operators like =, <> (not equal), >, <, >=, <=. +Logical operators such as AND, OR, and NOT can be used to combine multiple conditions. +**3. Pattern Matching:** The LIKE operator can be used for pattern matching. For example, LIKE 'A%' matches any string that starts with the letter 'A'. +**4. Range Checks:** The BETWEEN operator checks if a value is within a range of values. For example, BETWEEN 10 AND 20. +**5. Null Values:** The IS NULL and IS NOT NULL operators are used to filter records with null values. + +# Example of Where Clause in SQL + +Syntax: SELECT * from ; +Example : SELECT * from Students where marks >50; + +![Picture](image.png) + +**Where Clause use in Update Statement** +`UPDATE employees SET salary = salary * 1.10 +WHERE performance_rating = 'Excellent';` + +**Where Clause use in Delete Statement** +`DELETE FROM employees +WHERE last_login < '2023-01-01';` + + +**Where Clause use in Like Statement** +`SELECT * FROM customers +WHERE name LIKE 'J%';` + + +**Where Clause use in Between Statement** +`SELECT * FROM orders +WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31';` + + +**Where Clause use in IS NULL Statement** + +`SELECT * FROM employees +WHERE manager_id IS NULL;` + +# Conclusion +The WHERE clause in SQL is a powerful tool for filtering data in various SQL statements. It allows you to specify conditions that rows must meet to be included in the result set, thereby enabling precise data retrieval and manipulation. By using comparison operators, logical operators, pattern matching, range checks, and handling null values, you can create complex queries tailored to your specific data requirements. Mastering the WHERE clause is essential for efficient database management and analysis, providing the ability to focus on relevant data and perform targeted updates and deletions. \ No newline at end of file diff --git a/docs/SQL/image.png b/docs/SQL/image.png new file mode 100644 index 0000000000000000000000000000000000000000..0b5f4a9197a32ae63e865cb8f32bc06df1201784 GIT binary patch literal 15568 zcmcJ$Wl)|?w>5~n1`qDRA-KB}+}+(>gS&fh4{pKT-QC?Kxa-_J$@86>cdE{uGgb44 zg65*TuiZCm?OuEBP+4hFc$m*HKtMq7;$lMbKtLeUfbUnJKmcD+5kozIfCzxZh4>X+ zfq#3Aq?~Y6oQ)UC7t5yiV0lc>L}e2lf;k)Ce$;X1O;Xt*7+`(l?H*K2mW^i8Y>WVm zMj9X|KBG-upd^3h3r8PEqNKqE>#wbE`)(6^Lv}%eFw8v)WVNDn_Sw~DRQ3dsBa zw2At1YZU^_e_!6$f)J_vO#KnY2J}yWf{;U$S>e?F2?ii0ny|j6P7A{-uGoJ@=p*=Q zoAm|-{tcJvCF_J=&$~T-DZ4Cnq`cY| zYoRx+fjE8j#Pq)Vl!--*N70M2@EJTa?NLGoVtN7Or7Bw{|DEY^IpB9*d}S?%^jXJy z$vq*?hHJDWNSNUCT`WfvpOV!36Ki>_yaLOvJJyv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|qb&7<4tb@5J`?u(L zVFsAaivv`T_pgS+0MJy>L2-`%TK{+e2IyuP6N1yf%Ta$MyZSzYUVnE}2$=5v2rl6D z?{a+~ZwF^v^mjK8On~WlGJLE4E?0%=JAHgb`1V))hXOkTv=c){Prqz_oom4ZbSeXh M3rh=C2 Date: Sun, 23 Jun 2024 22:43:34 +0530 Subject: [PATCH 2/3] Commit 3 --- docs/SQL/SQL-Where-Clause.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/SQL/SQL-Where-Clause.md b/docs/SQL/SQL-Where-Clause.md index 50d99216a..722c0385a 100644 --- a/docs/SQL/SQL-Where-Clause.md +++ b/docs/SQL/SQL-Where-Clause.md @@ -1,4 +1,12 @@ -# Introduction to SQL WHERE Clause +--- +id: sql-where-clause +title: Where Clause in SQL +sidebar_label: Where Clause +sidebar_position: 3 +tags: [sql, database, clause ] +description: In this tutorial, you will learn how to build query with condition to get desired output. +--- + The WHERE clause in SQL is used to filter records from a result set. It specifies the conditions that must be met for the rows to be included in the result. The WHERE clause is often used in SELECT, UPDATE, DELETE, and other SQL statements to narrow down the data returned or affected. @@ -59,4 +67,14 @@ WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31';` WHERE manager_id IS NULL;` # Conclusion -The WHERE clause in SQL is a powerful tool for filtering data in various SQL statements. It allows you to specify conditions that rows must meet to be included in the result set, thereby enabling precise data retrieval and manipulation. By using comparison operators, logical operators, pattern matching, range checks, and handling null values, you can create complex queries tailored to your specific data requirements. Mastering the WHERE clause is essential for efficient database management and analysis, providing the ability to focus on relevant data and perform targeted updates and deletions. \ No newline at end of file +The WHERE clause in SQL is a powerful tool for filtering data in various SQL statements. It allows you to specify conditions that rows must meet to be included in the result set, thereby enabling precise data retrieval and manipulation. By using comparison operators, logical operators, pattern matching, range checks, and handling null values, you can create complex queries tailored to your specific data requirements. Mastering the WHERE clause is essential for efficient database management and analysis, providing the ability to focus on relevant data and perform targeted updates and deletions. + + +--- + +

Authors:

+
+ {['damini-chachane'].map(username => ( + + ))} +
\ No newline at end of file From a6cdbd2b16480f277ef686e97c524c315098df64 Mon Sep 17 00:00:00 2001 From: Ajay Dhangar <99037494+Ajay-Dhangar@users.noreply.github.com> Date: Mon, 24 Jun 2024 10:26:59 +0530 Subject: [PATCH 3/3] Update SQL-Where-Clause.md --- docs/SQL/SQL-Where-Clause.md | 132 ++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/docs/SQL/SQL-Where-Clause.md b/docs/SQL/SQL-Where-Clause.md index 722c0385a..047e38456 100644 --- a/docs/SQL/SQL-Where-Clause.md +++ b/docs/SQL/SQL-Where-Clause.md @@ -3,78 +3,84 @@ id: sql-where-clause title: Where Clause in SQL sidebar_label: Where Clause sidebar_position: 3 -tags: [sql, database, clause ] -description: In this tutorial, you will learn how to build query with condition to get desired output. +tags: [sql, database, clause] +description: In this tutorial, you will learn how to build queries with conditions to get the desired output. --- - The WHERE clause in SQL is used to filter records from a result set. It specifies the conditions that must be met for the rows to be included in the result. The WHERE clause is often used in SELECT, UPDATE, DELETE, and other SQL statements to narrow down the data returned or affected. -# Syntax -`SELECT column1, column2, ... +## Syntax +```sql +SELECT column1, column2, ... FROM table_name -WHERE condition;` - -# Operators Used in the Where Clause -1. `= : Equal`. -2. `> : Greater than`. -3. `< : Less than`. -4. `>= : Greater than or equal`. -5. `<= : Less than or equal`. -6. `<> : Not equal. Note: In some versions of SQL this operator may be written as !=`. -7. `BETWEEN : Between a certain range`. -8. `LIKE : Search for a pattern`. -9. `IN : To specify multiple possible values for a column`. -# Advantage of SQL WHERE Clause - -**1. Filtering Rows:** The WHERE clause evaluates each row in the table to determine if it meets the specified condition(s). Only rows that satisfy the condition are included in the result set. - -**2. Conditions:** Conditions in the WHERE clause can use comparison operators like =, <> (not equal), >, <, >=, <=. -Logical operators such as AND, OR, and NOT can be used to combine multiple conditions. -**3. Pattern Matching:** The LIKE operator can be used for pattern matching. For example, LIKE 'A%' matches any string that starts with the letter 'A'. -**4. Range Checks:** The BETWEEN operator checks if a value is within a range of values. For example, BETWEEN 10 AND 20. -**5. Null Values:** The IS NULL and IS NOT NULL operators are used to filter records with null values. - -# Example of Where Clause in SQL - -Syntax: SELECT * from ; -Example : SELECT * from Students where marks >50; - -![Picture](image.png) - -**Where Clause use in Update Statement** -`UPDATE employees SET salary = salary * 1.10 -WHERE performance_rating = 'Excellent';` - -**Where Clause use in Delete Statement** -`DELETE FROM employees -WHERE last_login < '2023-01-01';` - - -**Where Clause use in Like Statement** -`SELECT * FROM customers -WHERE name LIKE 'J%';` - - -**Where Clause use in Between Statement** -`SELECT * FROM orders -WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31';` - - -**Where Clause use in IS NULL Statement** - -`SELECT * FROM employees -WHERE manager_id IS NULL;` - -# Conclusion +WHERE condition; +``` + +## Operators Used in the WHERE Clause +1. `=` : Equal +2. `>` : Greater than +3. `<` : Less than +4. `>=` : Greater than or equal +5. `<=` : Less than or equal +6. `<>` : Not equal (Note: In some versions of SQL, this operator may be written as `!=`) +7. `BETWEEN` : Between a certain range +8. `LIKE` : Search for a pattern +9. `IN` : To specify multiple possible values for a column + +## Advantages of SQL WHERE Clause + +1. **Filtering Rows:** The WHERE clause evaluates each row in the table to determine if it meets the specified condition(s). Only rows that satisfy the condition are included in the result set. +2. **Conditions:** Conditions in the WHERE clause can use comparison operators like `=`, `<>` (not equal), `>`, `<`, `>=`, `<=`. Logical operators such as `AND`, `OR`, and `NOT` can be used to combine multiple conditions. +3. **Pattern Matching:** The LIKE operator can be used for pattern matching. For example, `LIKE 'A%'` matches any string that starts with the letter 'A'. +4. **Range Checks:** The BETWEEN operator checks if a value is within a range of values. For example, `BETWEEN 10 AND 20`. +5. **Null Values:** The `IS NULL` and `IS NOT NULL` operators are used to filter records with null values. + +## Examples of WHERE Clause in SQL + +### Basic Select Query +```sql +SELECT * FROM Students WHERE marks > 50; +``` + +### WHERE Clause in UPDATE Statement +```sql +UPDATE employees SET salary = salary * 1.10 +WHERE performance_rating = 'Excellent'; +``` + +### WHERE Clause in DELETE Statement +```sql +DELETE FROM employees +WHERE last_login < '2023-01-01'; +``` + +### WHERE Clause with LIKE Statement +```sql +SELECT * FROM customers +WHERE name LIKE 'J%'; +``` + +### WHERE Clause with BETWEEN Statement +```sql +SELECT * FROM orders +WHERE order_date BETWEEN '2023-01-01' AND '2023-12-31'; +``` + +### WHERE Clause with IS NULL Statement +```sql +SELECT * FROM employees +WHERE manager_id IS NULL; +``` + +## Conclusion The WHERE clause in SQL is a powerful tool for filtering data in various SQL statements. It allows you to specify conditions that rows must meet to be included in the result set, thereby enabling precise data retrieval and manipulation. By using comparison operators, logical operators, pattern matching, range checks, and handling null values, you can create complex queries tailored to your specific data requirements. Mastering the WHERE clause is essential for efficient database management and analysis, providing the ability to focus on relevant data and perform targeted updates and deletions. - --- -

Authors:

+## Authors: +
{['damini-chachane'].map(username => ( - ))} -
\ No newline at end of file + ))} +