IN, BETWEEN, LIKE operators in SQL
IN - defines a set of values.
SELECT * FROM Persons WHERE name IN ('Ivan','Petr','Pavel');
BETWEEN defines a range of values. Unlike IN, BETWEEN is order sensitive, and the first value in the sentence must be the first in alphabetical or numeric order.
SELECT * FROM Persons WHERE age BETWEEN 20 AND 25;
LIKE is applicable only to fields of type CHAR or VARCHAR with which it is used to find substrings. As a condition, wildcards are used - special characters that can match something:
- _ stands for any single character. For example, 'b_t' will match the words 'bat' or 'bit', but will not match 'brat'.
- % replaces a sequence of any number of characters. For example '%p%t' will match 'put', 'posit', or 'opt', but not 'spite'.
SELECT * FROM UNIVERSITY WHERE NAME LIKE '%o';
UNION keyword
In SQL, the UNION keyword is used to combine the results of two SQL queries into a single table of similar records. Both queries must return the same number of columns and compatible data types in the corresponding columns. It should be noted that UNION alone does not guarantee record order. The records from the second request may appear at the beginning, at the end, or even mix with the records from the first request. In cases where a specific ordering is required, use ORDER BY.
Read also:
Comments
Post a Comment