MySQL Basic statement

Source: Internet
Author: User

1. Limit is the syntax for MySQL
          Remove first record: SELECT * FROM tablename limit 0,1
          Remove the second record: SELECT * FROM tablename limit,
          11th to 31 (total 20): SELECT * FROM tablename limit 10,20
2. query sort (keywords: order by , ASC, DESC)

Example: select Name
From a
where chengji>=60
ORDER BY DESC
Note: The query table Chengji all rows that are greater than or equal to 60, and displays the name column in descending order; ASC ascending ORDER By default

3. Change the data using update updates

   Syntax: Update < table name > set < column name = update value > [where < update condition;]
Example: Update Tongxunlu set age =18 where name = ' Daniel '
Note: The set can be followed by updated values for multiple data columns, where clauses are optional, to restrict conditions, and if not selected, all rows of the entire table are updated

4. Delete some data using delete

Syntax: Delete from < table name > [where < delete condition;]
Example: Delete from a where name= ' Danny ' (delete rows in table A that have a column value of Daniel)
Note: Deleting an entire row does not delete a single field, so the field name cannot appear after the delete

5. Use TRUNCATE TABLE to delete data from the entire table

Syntax: TRUNCATE TABLE < name >
Example: Truncate TABLE Tongxunlu
Note: Delete all rows of the table, but the structure, columns, constraints, indexes, etc. of the table are not deleted;

6. Enquiry

1). Use like for fuzzy queries

Note: The LIKE operator uses only strings, so it is only used in conjunction with char and varchar data types
Example: SELECT * from a where name like ' Zhao% '
Description: The query shows a record of the first word in Table A, the Name field, for Zhao
 2). Use between to query within a range
Example: SELECT * from a where age between and 20
Description: The query displays a record of age from 18 to 20 in table a
 3). Use in to query within enumeration values
Example: select name from a where address in (' Beijing ', ' Shanghai ', ' Tangshan ')
Note: Query table A in the address value of Beijing or Shanghai or Tangshan records, display the Name field

4). Multi-table join query--INNER join

Specifying join conditions in the WHERE clause
Example: Select A.name,b.chengji
From a A B
where A.name=b.name
Description: Queries table A and table B for records with the same name field and displays the Name field in Table A and the Chengji field in table B

Select name as name, SUM (Value) as ' total ' from table group by Name

MySQL Basic statement

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.