W3schools - SQL_LIKE / Alias
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
LIKE
Is used in a WHERE clause to search for a specified pattern in a column
Two wildcards often used in conjunction with the LIKE operator
-
The percent sign(%) represents zero, one, or multiple characters
-
The underscore sign(_) represents on, single character
-
Can also be used in combinations
Syntax
SELECT column1, column2, …
FROM table_name
WHERE columnN LIKE pattern;
Wild card
Is used to substitute one or more chars in a string
Symbol | Desc |
---|---|
% | Represents zero or more chars |
_ | Represents a single char |
[] | Represents any single char within the brackets |
^ | Represents any char not in the brackets |
- | Represents any single char within the specified range |
Pattern | Desc |
---|---|
‘a%’ | Find values that start with “a” |
‘%a’ | Find values that end with “a” |
‘%a%’ | Find values that have “a” in any position |
‘_a%’ | Find values that have “a” in the second position |
‘a_%’ | Find values that start with “a” and are at least 2 chars in length |
‘a__%’ | Find values that start with “a” and are at least 3 chars in length |
‘a%o’ | Find values that start with “a” and ends with “o” |
IN
Allows to specify multiple values in a WHERE clause
Is shorthand for multiple OR conditions
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,…);
-- or
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
BETWEEN
Selects values within a given range. The values cans be numbers, text, or dates
Is inclusive: begin and end values are included
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Alias
Is used to give a table, or a column in a table, a temporary name
Only exists for the duration of that query
Is created with the AS keyword
Syntax
SELECT column_name AS alias_name
FROM table_name;
It requires double quotation marks or square brackets if the alias name contains spaces
-- Creates an alias named “Address” that combine four columns
SELECT CustomerName, Address + ‘,’ + PostalCode + ‘ ‘ + City + ‘,’ + Country AS Address
FROM Customers;
-- Alias for tables
SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName = ‘Around the Horn’ AND c.CustomerID = o.CustormerID;