Operators and Expressions
DBMS Tutorial 3.1
SQL Basics
Arithmetic Operators:
Operator
|
Symbol
|
Usage
|
Result
|
Addition
|
+
|
15 + 5
|
20
|
Subtraction
|
-
|
15 - 5
|
10
|
Multiplication
|
*
|
15 * 5
|
75
|
Division
|
/
|
15 / 5
|
3
|
Comparison Operators:
Operator
|
Symbol
|
Usage
|
Result
|
Equal to
|
=
|
15 = 5
|
false
|
Not equal to
|
<>
|
15 <> 5
|
true
|
Greater than
|
>
|
15 > 5
|
true
|
Greater than equal to
|
>=
|
15 >= 5
|
true
|
Less than
|
<
|
15 < 5
|
false
|
Less than equal to
|
<=
|
15 <= 5
|
false
|
Note: There is one important difference between Equal To comparison operator in programming languages and SQL. While SQL uses a single '=', programming languages typically use double '=' to distinguish it from the assignment operator.
Operation
|
Python Operator
|
SQL Operator
|
Assignment
|
=
|
=
|
Equality check
|
==
|
=
|
Other Comparison Operators:
Operator
|
Symbol
|
Usage
|
Example
|
Range
|
BETWEEN <lower limit> AND <upper limit>
|
Matches value between a range of values (Both inclusive)
|
Salary BETWEEN 2500 AND 3000
|
List
|
IN (List of values)
|
Matches any of a list of values
|
Dept IN ('IVS', 'ETA', 'ICP')
|
String pattern matching
|
LIKE
|
Matches a character pattern
|
SupplierId LIKE 'S%'
|
NULL Test
|
IS NULL
|
Is a null value
|
Bonus IS NULL
|
Logical Operators:
Operator
|
Symbol
|
Usage
|
Example
|
And
|
AND
|
Returns TRUE if both conditions are true
|
Salary >= 30000 AND Dept = 'ETA'
|
Or
|
OR
|
Returns TRUE if any one of the condition is true
|
Salary > 75000 OR Dept = 'ICP'
|
Not
|
NOT
|
Returns TRUE if the following condition is false
|
Id NOT IN (2,3)
|
Expressions:
Similar to arithmetic expressions in programming languages, SQL expressions are created from constant values, operators, and brackets. They evaluate to a single value and are used in SELECT and WHERE clauses. Some examples are provided below:
Operators and Expressions
DBMS Tutorial 3.1
Back Next
---
I hope you likable this nice post. Do not forget to share it together with your friends, the Sharing Button is below the post. Apart from this, if there's any downside within the intermediate, don't hesitate to request the Comment Box. we are going to be happy to help you.
I will continue to write more and more on this blog, so do not forget to make our blog BlogLearner as a bookmark (Ctrl + D) on your mobile or computer and subscribe to us to get all the posts in your email. Do not forget to share these posts, if you like it. You can facilitate us reach additional individuals by sharing it on social networking sites like Facebook or Twitter.
Operators and Expressions - SQL Basics |
No comments:
Post a Comment