Operators

Logical Operators

OperatorsDescription

LIKE

allows you to perform operations similar to using WHERE and =, but for cases when you might not know exactly what you are looking for.

IN

allows you to perform operations similar to using WHERE and =, but for more than one condition.

NOT

used with IN and LIKE to select all of the rows NOT LIKE or NOT IN a certain condition.

AND & BETWEEN

allow you to combine operations where all combined conditions must be true.

OR

allows you to combine operations where at least one of the combined conditions must be true.

Set Operators

OperatorsDescription

UNION/UNION ALL

combines and returns the result-set retrieved by two or more SELECT statements.

MINUS/EXCEPT

removes the duplicates from the results of the second SELECT query from the results of the first SELECT query and then returns the filtered result from the first query.

INTERSECT

combines the result fetched by the two SELECT statements where records from one match the other and then returns this intersection of result-sets.

Before any of the above operations are performed the following conditions should be followed

  • Each SELECT statement must have the same number of columns

  • The columns must also have the similar data types

  • The columns in each SELECT statement should be in the same order

UNION operation removes duplicates from the final result, whereas UNION ALL operation does not remove duplicates and displays all the data.

NULL are different than a zero - they are cells where data does not exist. When identifying NULLs in a WHERE clause, we write IS NULL or IS NOT NULL. We don't use =, because NULL isn't considered a value in SQL. Rather, it is a property of the data.

Last updated