Skip to content

Commit

Permalink
Improve Comparison Operator and function Document for IN operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanksha-kedia authored and tdcmeehan committed Sep 7, 2023
1 parent 13b2f5c commit 3d3b1d0
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion presto-docs/src/main/sphinx/functions/comparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ specified for the ESCAPE parameter. Matching is case sensitive.

Syntax::

expression LIKE pattern [ ESCAPE 'escape_character' ]
expression LIKE pattern [ ESCAPE 'escape_character' ]

if ``pattern`` or ``escape_character`` is null, the expression evaluates to null.

Expand Down Expand Up @@ -198,3 +198,62 @@ Examples::
SELECT * FROM (VALUES ('a%c'), ('%cd'), ('cde')) AS t (name)
WHERE name LIKE '%#%%' ESCAPE '#'
--returns 'a%c' and '%cd'


Row comparison: IN
------------------

The IN comparison operator in SQL is used to compare a value with a list of literal values that have been specified.
The IN operator returns TRUE if the value matches any of the literal values in the list. The IN operator can be
used to compare values with the following patterns. It can fetch records according to multiple values specified in
WHERE clause. A sub-query or list of values must be specified in the parenthesis, however one column must be specified
in the sub-query.

.. code-block:: none
WHERE column [NOT] IN ('value1','value2');
WHERE column [NOT] IN ( subquery )
Examples::

SELECT * FROM region WHERE name IN ('AMERICA', 'EUROPE');

SELECT * FROM region WHERE name IN ('NULL', 'AMERICA', 'EUROPE');

SELECT * FROM table_name WHERE (column1, column2) IN ((NULL, 'value1'), ('value2', 'value3'));


Row comparison: OR
------------------

The OR operator is used to filter the results of a query based on more than one condition.
It returns a record if any of the conditions separated by OR is TRUE.
The values in the clause are used for multiple comparisons that are combined as
a logical OR. The preceding query is equivalent to the following query:

Example::

SELECT * FROM region WHERE name = 'AMERICA' OR name = 'EUROPE';


Row comparison: NOT IN
------------------

The NOT IN comparison operator in SQL is used to exclude the rows that match any value in a list or subquery.

You can negate the comparisons by adding NOT, and get all other regions
except the values in list:

Example::

SELECT * FROM region WHERE name NOT IN ('AMERICA', 'EUROPE');


When using a subquery to determine the values to use in the comparison, the
subquery must return a single column and one or more rows.


Example::

SELECT id, name FROM region WHERE name IN (SELECT name FROM region WHERE id IN (3,4));

0 comments on commit 3d3b1d0

Please sign in to comment.