MySQL Basic knowledge _2

Source: Internet
Author: User

    • MySQL query data
SELECT column name , column name from table name [Clause][LIMIT N] [ OFFSET M]   
    1. You can use one or more tables in a query statement, split between tables using commas (,), and use the where statement to set the query criteria.
    2. The SELECT command can read one or more records.
    3. You can use an asterisk (*) instead of another field, and the SELECT statement returns all the field data for the table.
    4. You can use the WHERE statement to include any condition.
    5. You can use the LIMIT property to set the number of records returned.
    6. You can specify the data offset for the SELECT statement start query by using offset. By default, the offset is 0.
SELECT ' name ', result from  ta,tb  WHERE ' name ' = ' Zhang San ' LIMIT 3  OFFSET 3;

The limit is followed by 3 data, and offset is read from the 3rd bar.

    • MySQL WHERE clause
select column name 1,< Span class= "PLN" > column name 2,...  column name n from table 1, table 2 ... [where conditions 1 [and [or]] conditions 2 ..... 
/span>
    1. You can use one or more tables in a query statement, split between tables using commas (,) , and use the where statement to set the query criteria.
    2. You can specify any condition in the WHERE clause.
    3. You can specify one or more conditions by using and OR OR.
    4. The WHERE clause can also be applied to the SQL Delete or UPDATE command.
    5. The WHERE clause is similar to the IF condition in a program language, and reads the specified data according to the field values in the MySQL table.
SELECT ' name ', result from  ta,tb  WHERE ' name ' = ' Zhang San ' OR ' name ' = ' John Doe ';

The conditional operator of the WHERE clause can be = (equals sign), <>,! = (not Equal), > (greater than Sign), < (less than), >= (greater than equals), <= (less than equals).

    • MySQL UPDATE Query
UPDATE table Name set column Name 1= new column value 1, column Name 2= new column value 2[Clause]      
    1. You can update one or more fields at the same time.
    2. You can specify any condition in the WHERE clause.
    3. You can update the data at the same time in a separate table.
UPDATE ta SET name= ' King II leper ' WHERE user_id= ' 1002 ';
    • MySQL DELETE Statement
[Clause] 
    1. If you do not specify a WHERE clause, all records in the MySQL table will be deleted.
    2. You can specify any condition in the WHERE clause.
    3. You can delete records at once in a single table.
DELETE from Ta WHERE user_id= ' 1002 ';
    • MySQL LIKE clause
select column name 1,< Span class= "PLN" > column name 2,...  column name n from table name where column name 1 like condition 1 [and [or]] column name 2 =  ' Column value '               
    1. You can specify any condition in the WHERE clause.
    2. You can use the LIKE clause in the WHERE clause.
    3. You can use the LIKE clause instead of equal sign =.
    4. Like is usually used in conjunction with%, similar to a meta-character search.
    5. You can specify one or more conditions by using and OR OR.
    6. You can use the where ... in the DELETE or UPDATE command. The LIKE clause to specify the condition.
SELECT Name,result from TA,TB  WHERE ' name ' like '% ' of ' OR ' name ' like '% Li ';

  

MySQL Basic knowledge _2

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.