Oracle SQL in 10 Minutes - Asim Abbasi
CH1: SQL Basics | CH2: SQL Operators | CH3: SQL Built-in Functions | CH4: SQL Joins | CH5: UPDATE, INSERT & DELETE Statements | CH6: CREATE, ALTER & DROP Statements | CH7: Constraints | CH8: Linking Tables vs Joining Tables | CH9: SQL Statements for Other Database Objects | CH10: SQL Statements for Database Security
Chapter 2: SQL Operators

Figure 4: SQL Operators: Comparison, Arithmetic,
Logical & Other.
________________________________________
Just like we used the greater than (>) operator in the previous
examples, there are other SQL operator too. They are mostly used in the
WHERE clause to filter certain records or to reduce the number of
records in the output. “Reduce the number of records”, what this means?
Why we need to reduce the number of records in the output. Imagine a SSA
(Social Security Administration) office. The database they are having
must be having millions of records in it. You can well realize the
drawback, if someone would execute the following statement.
SELECT *
FROM ssa;
Another aspect is, why to look at something you don’t need. If you are
looking someone’s information then why to execute the query that will
give you all the records rather than execute the following query.
SELECT *
FROM ssa
WHERE ssn = ‘123-455-6677’;
The way we have used the “greater than” operator, on the same lines we
can use the “less than” (<), “equal to” (=), “less than equal to” (<=) &
“greater than equal to” (>=). ANY/SOME and ALL can be best understood by
first looking at their respective real world example.
Example:
SELECT *
FROM emp
WHERE sal = ANY (SELECT sal
FROM emp
WHERE deptno = 30);
Compares a value to each value in a list or returned by a query. Must be
preceded by =, !=, >, <, <=, >=. Evaluates to FALSE if the query returns
no rows.
Example:
SELECT *
FROM emp
WHERE sal >= ALL ( 1400, 3000);
Compares a value to every value in a list or returned by a query. Must be preceded by =, !=, >, <, <=, >=. Evaluates to TRUE if the query returns no rows.
Chapter 1: SQL Operators
CH1: SQL Basics | CH2:
SQL Operators |
CH3: SQL Built-in Functions | CH4:
SQL Joins | CH5:
UPDATE, INSERT & DELETE Statements |
CH6: CREATE, ALTER & DROP Statements | CH7:
Constraints | CH8:
Linking Tables vs Joining Tables | CH9:
SQL
Statements for Other Database Objects | CH10:
SQL Statements for
Database Security Share with others: