The WILDCARD operator is in SQL
WILDCARD , also known as a wildcard, is used in conjunction with the LIKE statement in SQL to compare a value with similar values.
SQL supports two representation operators associated with the LIKE operator as percent sign (%) and underscore (_).
Wildcard Description Percentage symbol (%) Represents one or more characters.Note : MS Access uses an asterisk character (*) to replace the percentage character (%) Underscore (_) Represents a single character.
Note : MS Access uses a question mark (?) Instead of underscores (_)
A percent sign can represent a string of characters of any length (including length 0). An underscore represents a number or a character. These symbols can be used in combination.
The syntax for using WILDCARD in SQL
The basic syntax of '%' and '_' is as follows:
SELECT FROM ten_bang
WHERE cot LIKE 'XXXX%'
or:
SELECT FROM ten_bang
WHERE cot LIKE '%XXXX%'
or:
SELECT FROM ten_bang
WHERE cot LIKE 'XXXX_'
or:
SELECT FROM ten_bang
WHERE cot LIKE '_XXXX'
or:
SELECT FROM ten_bang
WHERE cot LIKE '_XXXX_'
You can combine N conditions using AND or OR operators. Here, XXXX can be any numeric or string value.
Example of WILDCARD operator
The following table has a few examples showing the WHERE clause has a LIKE clause with different WILDCARD '%' and '_' operators:
STT Statement and description 1 WHERE SALARY LIKE '200%'Find all values starting with 200. 2 WHERE SALARY LIKE '% 200%'
Find all values that have 200 any position. 3 WHERE SALARY LIKE '_00%'
Find all values that have 00 in the second and third positions. 4 WHERE SALARY LIKE '2 _% _%'
Find all values that begin with 2 and have at least 3 characters. 5 WHERE SALARY LIKE '% 2'
Find all values ending in 2. 6 WHERE SALARY LIKE '_2% 3'
Find all values with position 2 in the second position and end with 3. 7 WHERE SALARY LIKE '2___3'
Find all values in the five-digit number beginning with 2 and ending with 3.
Let us take a practical example, considering the table NHANVIEN has the following records:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 1 | Thanh | 32 | Haiphong | 2000.00 | | 2 | Loan | 25 | Hanoi | 1500.00 | | 3 | Nga | 23 | Hanam | 2000.00 | | 4 | Manh | 25 | Hue | 6500.00 | | 5 | Huy | 27 | Hatinh | 8500.00 | | 6 | Cao | 22 | HCM | 4500.00 | | 7 | Lam | 24 | Hanoi | 10000.00 | +----+----------+-----+-----------+----------+
The example shows all the records from the NHANVIEN table that LUONG starts with 200, we do the following:
SQL> SELECT * FROM NHANVIEN
WHERE LUONG LIKE '200%';
The returned result is:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 1 | Thanh | 32 | Haiphong | 2000.00 | | 3 | Nga | 23 | Hanam | 2000.00 | +----+----------+-----+-----------+----------+
In the next section, we will learn about the functions that handle Date in SQL , so please keep track.
Last post: TRANSACTION in SQL
Next article: Function handling DATE / TIME in SQL - Part 1
You should read it
- The '+' operator in SQL Server
- Operator in programming C
- What kind of SSL certificate does your website need?
- Overload the one-seat operator in C ++
- Load operator ++ and - in C ++
- How to rename a drive, change the drive letter in Windows
- Overload subscript operator [] in C ++
- Operator overload and Load overlap in C ++
May be interested
- How to Get Compensation from a BUI Accidentif you were injured in a boating accident, then you can sue the boat operator who caused the injury. for example, the operator may have hit your own boat, or you may have been in the boat with the operator who was intoxicated. either way,...
- Stack operator in Pythonyou can change the meaning of the operator in python depending on the operand used and we call that operator overloading. quantrimang will learn more about this content through the article. invites you to read the track.
- OpenAI Announces Operator, an AI Agent That Automatically Performs Tasks on User's Behalfthe company behind chatgpt is unveiling a new way to use ai. openai has just announced operator, an ai agent that can automatically perform tasks for you.
- EXCEPT operator in SQL Serverthe except operator in sql server is used to return the rows in the first select statement that are not returned in the second select statement.
- Operator in JavaScriptwe see the following simple expression: 4 + 5 is equal to 9. here 4 and 5 are operands and '+' called operator - operator.
- UNION operator in SQL Serverthis tutorial explains how to use the union operator in sql server with specific syntax and examples.
- Speedtest announces VNPT as Vietnam's No. 1 Internet network operatorduring the test, vnpt achieved download speed of 64mbps and upload speed of 65.07mbps.
- How to Drive an Excavatoran excavator is a large piece of machinery used to dig dirt and debris out of construction sites. using one on a construction site requires operator training and a state operator license.https://study.com/articles/become_an_excavator_edu...
- How to chat with Viettel operatorviettel customers can access viettel.vn website to chat directly with viettel operator in the fastest way and completely free instead of having to call the switchboard to get assistance. this new way of not only helps you save costs (no call charges) but also helps your phone to easily understand what you are asking.
- How to Become an Owner Operator Truck Driveran owner operator owns or leases a truck and hauls goods for client companies. if you want to start a trucking business, choose a niche market, such as logging or hazardous materials. project your costs and revenue to see how many...