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.
Examples of LIKE in SQL The following table has a few examples that show the WHERE clause has a LIKE clause with different '%' 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's take a practical example, consider the NHANVIEN table with the records as below.
+----+----------+-----+-----------+----------+ | 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 TOP command, remember to follow it.
Previous article: DELETE command in SQL
Next lesson: TOP command in SQL
RELATED POSTS the del command deletes one or more files. this command is the same as the eraser command.
command prompt is an extremely familiar command for anyone using windows operating system. besides, a lot of current software also supports the command line to perform actions on the command prompt window, instead of on the screen.
the set command helps show, set or remove cmd.exe environment variables.
the cmd command starts a new version of the command interpreter, cmd.exe. if used without parameters, cmd will display copyright information and the version of the operating system.
the bitadmin getdisplayname command takes the display name of the specified task. the bitsadmin geterror command retrieves detailed error information for the specified job.
the echo command displays the message or turns on / off the command repeat feature. if used without parameters, the echo command will display the current echo setting.
the fc command compares two files or a collection of files and displays the differences between them.
the at command schedules commands and programs to run on a computer at a specified time with a specific date. you can only use the command at when schedule service is running.
the doskey command calls doskey.exe (which reminds of previously entered command lines), modifies the command line and creates macros.
command prompt is used to execute batch files, perform tasks quickly, help you troubleshoot and solve some windows problems when the system crashes. however, not all commands in windows are useful and must be done regularly. with the 10 command lines in the following article it is very useful even if you are not an administrator.
the which command in linux determines the executable binary, which will execute when you issue a command to the shell. if you have different versions of the same program on your computer, you can use which to find out which shell will use.
the reg add command adds new subkeys or entries to the registry.