In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to use in in the select sentence of mysql". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In mysql, in within select statements is often used in where expressions to query data within a certain range. The scope data of in queries is not necessarily explicit and may contain subquery statements with the syntax "select * from where...in (range data or subquery statements)".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
What is the use of in in the select statement of mysql
I. basic usage
In in mysql is often used in where expressions to query data within a range.
Select * from where field in (value1,value2,value3, …)
When IN is preceded by the NOT operator, it means the opposite of IN, that is, do not select in these list items
Select * from where field not in (value1,value2,value3, …)
2. IN subquery
More often, the value of the IN list item is ambiguous and may be obtained through a subquery:
SELECT * FROM article WHERE uid IN (SELECT uid FROM user WHERE status=0)
In this SQL example, we have implemented all articles that find out all users with a status of 0 (possibly prohibited). First, get all the users of status=0 through one query:
SELECT uid FROM user WHERE status=0
Then use the query result as a list item of IN to achieve the final query result, note that the result returned in the subquery must be a field list item.
Example: query all data with id 2 and 4 in the book table:
There is a book data sheet, which contains the following contents:
The query statement and the query results are shown in the following figure:
This is the end of the content of "how to use in in the select sentence of mysql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.