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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the basic query sentences of SQL". In the daily operation, I believe that many people have doubts about the basic query sentences of SQL. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what are the basic query sentences of SQL?" Next, please follow the editor to study!
1. Basic SELECT statement 1. Query specified fields
Syntax format:
SELECT,... FROM
Multiple fields can be specified in the statement, and the results are displayed according to the specified fields.
For example, query the user's id, user name, nickname and gender information in the users user table:
SELECT user_id,user_name,nick_name,sex FROM users
2. Query all fields
Viewing all fields in a table can be indicated by an asterisk "*", for example, the following statement queries all data in the users user table:
SELECT * FROM users
"*" represents all fields. When parsing the statement, the database will extend it with the field name in the table and replace "*" with the fields of user_id, user_name, nick_name, sex, mobile, email and other tables according to the actual situation.
3. Set aliases
Use the AS keyword to set aliases for columns.
SELECT user_id AS id,user_name AS user name, nick_name AS nickname, sex AS gender FROM users
4. Query of constants
You can write not only column names but also constants in SELECT statements.
As follows:
SELECT 100 select 'user'; 5. Query the expression SELECT 980 * * 6, remove duplicates
The DISTINCT keyword can be used in the SELECT statement to remove duplicate records from the query results, for example, to remove user_name duplicated data:
SELECT DISTINCT user_name FROM users
Note: DISTINCT does not filter NULL, that is, the returned result contains a null value
When DISTINCT is applied to multiple columns, the scope of application is all the fields that follow it, and DISTINCT can only be placed in front of all fields, that is, before the first column name.
SELECT DISTINCT user_name,nick_name FROM users;7, conditional query
The SELECT statement queries records that meet the specified criteria through the WHERE clause, with the WHERE clause immediately following the FROM clause.
SELECT,... FROM WHERE; 7.1 single conditional query
Query users whose gender is male:
SELECT * FROM users WHERE sex=' male'
Query users younger than or equal to 24:
SELECT * FROM users WHERE age
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.