In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the usage of select sentence in MySQL database". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of select sentence in MySQL database.
Select statements can be separated by carriage returns
Both $sql= "select * from article where id=1" and $sql= "select * from article where id=1" can get the correct results, but sometimes it may be clearer to write separately, especially if the sql statement is longer.
Batch query data
You can use in to implement $sql= "select * from article where id; in"
Use concat to join the results of a query
$sql= "select concat (id,"-", con) as res from article where id=1" returns "1-article content"
Use locate
Usage: select locate ("hello", "hello baby"); return 1 does not exist return 0
Use group by
Group by and order by have not been known much before, but it is actually quite simple. Group by compiles the same results into a group of exam:$sql= "select city, count (*) from customer group by city". The idea of this sentence is to list all the cities that do not repeat from the customer table, and their number (similar to distinct). Group by is often used with AVG (), MIN (), MAX (), SUM (), COUNT ().
Use having
Having allows conditional aggregation of data into groups $sql= "select city,count (*), min (birth_day) from customergroup by city having count (*) > 10". This sentence is grouped by city, and then finds the city btw where the number of city sites is greater than 10: using group by + having is a bit slow and the expression contained in the having clause must have appeared before.
Combination clause
Where, group by, having, order by (usually in this order if all four are to be used)
Use distinct
Distinct is $sql= "select distinct city from customer order by id desc" used to remove duplicate values; this sentence means to query all non-repeating city https://www.linuxprobe.com/chapter-18.html from the customer table.
Use limit
If you want to display all records after a record $sql= "select * from article limit 100penny-1"
Multi-table query
$sql= "select user_name from user ujim membe r mwhere u.id=m.id and m.reg_date >; = 2006-12-28order by u.id desc"
Note: if both the user and member tags have a user_name field, there will be a mysql error (because mysql does not know which table you want to query in the bottom), and you must specify which table it belongs to.
Thank you for reading, the above is the content of "the usage of select sentence in MySQL database". After the study of this article, I believe you have a deeper understanding of the usage of select sentence in MySQL database, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.