当前位置:网站首页>10. Learn MySQL like clause
10. Learn MySQL like clause
2022-07-28 09:04:00 【Microservice spring cloud】
MySQL LIKE Clause
We know that MySQL Use in SQL SELECT Command to read data , At the same time, we can go to SELECT Use in statement WHERE Clause to get the specified record .
WHERE An equal sign can be used in a clause = To set the conditions for obtaining data , Such as "xxxxxx_author = 'XXXXXX.COM'".
But sometimes we need to get xxxxxx_author Field contains "COM" All records of characters , Then we need to WHERE Used in clauses SQL LIKE Clause .
SQL LIKE Use percent sign in Clause % Character to represent any character , Be similar to UNIX Or an asterisk in a regular expression *.
If you don't use the percent sign %, LIKE Clause and equal sign = The effect is the same .
grammar
Here are SQL SELECT Statements use LIKE Clause to read data from a data table :
SELECT field1, field2,...fieldN
FROM table_name
WHERE field1 LIKE condition1 [AND [OR]] filed2 = 'somevalue'- You can WHERE Clause to specify any condition .
- You can WHERE Used in clauses LIKE Clause .
- You can use LIKE Clause instead of equal sign =.
- LIKE Usually with % Use together , Similar to a metacharacter search .
- You can use AND perhaps OR Specify one or more conditions .
- You can DELETE or UPDATE Use in command WHERE...LIKE Clause to specify the condition .
Use... At the command prompt LIKE Clause
Below we will be in SQL SELECT Use in command WHERE...LIKE Clause comes from MySQL Data sheet xxxxxx_tbl Read data from .
example
Here is what we will xxxxxx_tbl Table acquisition xxxxxx_author In the field, use COM For all records at the end :
SQL LIKE sentence :
mysql> use XXXXXX;
Database changed
mysql> SELECT * from xxxxxx_tbl WHERE xxxxxx_author LIKE '%COM';
+-----------+---------------+---------------+-----------------+
| xxxxxx_id | xxxxxx_title | xxxxxx_author | submission_date |
+-----------+---------------+---------------+-----------------+
| 3 | Study Java | XXXXXX.COM | 2021-11-20 |
| 4 | Study Python | XXXXXX.COM | 2021-11-21 |
+-----------+---------------+---------------+-----------------+
2 rows in set (0.01 sec)stay PHP Use in script LIKE Clause
You can use PHP Functional mysqli_query() And the same SQL SELECT close WHERE...LIKE Clause to get data .
This function is used to execute SQL command , And then through PHP function mysqli_fetch_array() To output all the query data .
But if it is DELETE perhaps UPDATE Use in WHERE...LIKE Clause S QL sentence , No need to use mysqli_fetch_array() function .
example
Here's how we use PHP Script in xxxxxx_tbl Read... In table xxxxxx_author In the field, use COM For all records at the end :
MySQL LIKE Clause test :
<?php
$dbhost = 'localhost'; // mysql Server host address
$dbuser = 'root'; // mysql user name
$dbpass = '123456'; // mysql User name, password
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die(' The connection fails : ' . mysqli_error($conn));
}
// Set encoding , Prevent Chinese miscoding
mysqli_query($conn , "set names utf8");
$sql = 'SELECT xxxxxx_id, xxxxxx_title,
xxxxxx_author, submission_date
FROM xxxxxx_tbl
WHERE xxxxxx_author LIKE "%COM"';
mysqli_select_db( $conn, 'XXXXXX' );
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die(' Unable to read data : ' . mysqli_error($conn));
}
echo '<h2>xx course mysqli_fetch_array test <h2>';
echo '<table border="1"><tr><td> course ID</td><td> title </td><td> author </td><td> Submission date </td></tr>';
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))
{
echo "<tr><td> {$row['xxxxxx_id']}</td> ".
"<td>{$row['xxxxxx_title']} </td> ".
"<td>{$row['xxxxxx_author']} </td> ".
"<td>{$row['submission_date']} </td> ".
"</tr>";
}
echo '</table>';
mysqli_close($conn);
?>边栏推荐
- Div tags and span Tags
- Chapter 2-2 calculation of piecewise function [1]
- [advanced drawing of single cell] 07. Display of KEGG enrichment results
- Recycling of classes loaded by classloader
- Argocd Web UI loading is slow? A trick to teach you to solve
- Huid learning 7: Hudi and Flink integration
- MDM data quality application description
- There is a bug in installing CONDA environment
- Will sqlserver CDC 2.2 generate table locks when extracting large tables from the source
- Feign调用异常[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = n]
猜你喜欢

Principle of line of sight tracking and explanation of the paper

Basic syntax of jquey

训练一个自己的分类 | 【包教包会,数据都准备好了】

Bluetooth technology | it is reported that apple, meta and other manufacturers will promote new wearable devices, and Bluetooth will help the development of intelligent wearable devices

图片批处理|必备小技能

Smart software completed round C financing, making Bi truly "inclusive"
![Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]](/img/97/6c3662ef36b02bc42eec95abaa6bc5.png)
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]

Line generation (matrix)

快速搭建一个网关服务,动态路由、鉴权的流程,看完秒会(含流程图)

DIY system home page, your personalized needs PRO system to meet!
随机推荐
Explain cache consistency and memory barrier
JSON file storage
Two dimensional array and operation
What are the main uses of digital factory management system
Distributed system architecture theory and components
[activity registration] User Group Xi'an - empowering enterprise growth with modern data architecture
Setting of parameter configuration tool for wireless vibrating wire collector
What content does the new version of network security level protection evaluation report template contain? Where can I find it?
478-82(56、128、718、129)
侯捷STL标准库和泛型编程
Baidu AI Cloud Jiuzhou district and county brain, depicting a new blueprint for urban and rural areas!
Go interface Foundation
Huid learning 7: Hudi and Flink integration
Why can ThreadLocal achieve thread isolation?
Code management platform SVN deployment practice
剑指offer
Prometheus TSDB analysis
训练一个自己的分类 | 【包教包会,数据都准备好了】
c语言数组指针和指针数组辨析,浅析内存泄漏
看完这12个面试问题,新媒体运营岗位就是你的了