当前位置:网站首页>How to use the select statement of MySQL
How to use the select statement of MySQL
2022-06-29 04:22:00 【Yisu cloud】
MySQL Of select How to use statements
This article “MySQL Of select How to use statements ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “MySQL Of select How to use statements ” Article bar .

select Statement can To separate... With carriage return
$sql="select * from article where id=1" and $sql="select * from article where id=1" Can get the right results , But sometimes writing separately may More clearly , Especially when sql When the statement is long .
Bulk query data
It can be used in To achieve $sql="select * from article where id ;in(1,3,5)"
Use concat Connect the results of the query
$sql="select concat(id,"-",con) as res from article where id=1" return "1-article content"
Use locate
usage : select locate("hello","hello baby"); return 1
There is no return 0Use group by
I haven't figured it out before group by and order by, It's actually quite simple ,group by Is to tie the same knot Make the fruit into a group exam:$sql="select city ,count(*) from customer group by city"; The meaning of this sentence is Thinking is from customer The table lists all cities that do not repeat , And quantity ( It's kind of similar distinct) group by Often with AVG(),MIN(),MAX(),SUM(),COUNT() Use it together
Use having
having Allow conditional aggregation of data into groups $sql="select city,count(*),min(birth_day) from customer group by city having c ount(*)>10"; This sentence is to press city Grouping , Then find out city The quantity of land is greater than 10 The city of City btw: Use group by + having It's a little slow Same as when having Clause must contain an expression that has occurred before
Combined clause
where、 group by、having、order by( If you want to use all four , Usually press this In one order )
Use distinct
distinct It is used to remove duplicate values $sql="select distinct city from customer order by id desc"; This sentence means from customer Look up in the table Ask for all non repetitive city
Use limit
If you want to display the information after a record Records $sql="select * from article limit 100,- 1";
Multi-table query
$sql="select user_name from user u,membe r m where u.id=m.id and m.reg_date> ;=2006-12-28 order by u.id desc"
Be careful : If user and member Both labels have user_name Field , There will be mysql error ( because mysql I didn't know you were there Which table do you want to query user_name), You must indicate which table it belongs to .
That's about “MySQL Of select How to use statements ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- 直播预约|AWS Data Everywhere 系列活动
- Ling Jing thinks about her own way
- Analysis of moudo Network Library
- Hi, my technology forum is online!
- Call snapstateon closed sou from Oracle CDC
- What is the dry goods microservice architecture? What are the advantages and disadvantages?
- 请问大佬,Oracle CDC报错 Call snapshotState on closed sou
- [new function] ambire wallet integrates Metis network
- 1017 A除以B分
- Log in to the MySQL database and view the version number on the command line
猜你喜欢
随机推荐
如何创建 robots.txt 文件?
LabVIEW显示Unicode字符
ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster
Binary tree serialization and deserialization (leetcode (difficult))
Error accessing database
[C language] explain the thread recycling function pthread_ join
SQL database stored procedure writing method
Pytorch read / write file
PostgreSQL has a cross database references are not implemented bug
树莓派用VNC Viewer方式远程连接
CTO and programmer were both sentenced because the crawler was out of control!
Blue Bridge Cup DFS (I)
自己动手搭建一个简单的网站
Sword finger offer II 040 Largest rectangle in matrix
Project development culture
JSX的基本使用
Idea modifying JVM memory
选对学校,专科也能进华为~早知道就好了
[laravel series 8] out of the world of laravel
【HackTheBox】dancing(SMB)









