MySQL-Data query statements

Source: Internet
Author: User

Data query Statements
Select column name, column name, column name ... from table name [where condition]
The column name is the name of the field, note that the last column name does not have a comma, the condition after the table name can be added without adding the data that is only found to satisfy the condition.


Querying user names and passwords in the user table
Select User_name,password from user;
This is only the user name and password in the table, and no conditions

Add a Where condition to isolate all fields that meet the criteria
SELECT * from user where id=1;

Filter out duplicate values
Select distinct mobile from user;
Filter the Mobile field in the user table, and repeat it to find only one

Link fields
Select Concat (user_name,mobile) from user;
Connect the user_name and cell phone number into a single field

Specify the name of the field after the connection
Select Concat (user_name,email) as user_name_email from user;

Add a separator to a field--
Select Concat_ws ("--", user_name,email) from user;


Field Rename
Select User_name as name,email as em from user;
Rename the Found field user_name to name to rename the email to EM


Fuzzy query (scenario: Search)
Like applies to queries with small data volumes (less than 100,000)
Using Sphinx (another technology) with a large amount of data
Select user_name from user where user_name like '%ng% ';
Query the value of the field with the User_name field value,% represents whatever is behind you, as long as value is in this NG will be detected.
%ng represents the left fuzzy ng% represents the right fuzzy%ng% represents the whole fuzzy

---------------------------------------------------

MySQL-Data query statements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.