My PHP Tour--sql statement

Source: Internet
Author: User

SQL statements

Structured Query Language (structured query Language) is called SQL, which is a language for manipulating data.

Add record
    • INSERT into table_name(field 1, Field 2, Field 3) VALUES (value 1, value 2, value 3);
      • The field corresponds to a value of one by one.
      • An increase in records can only be added to one article.
      • If no fields are listed, they will be replaced with default values.
        • Example: INSERT INTO News (title,content) VALUES (' Some titles ', ' some content ');

Deleting Records
    • DELETE from table_name[WHERE condition];
    • delete from news; //Delete all data in the table.
    • Delete from news where id>10; //delete data with IDs greater than 10.
    • Delete from news where id>10 and id<35; //delete data with IDs greater than 10 and less than 35.
    • Delete from news where author= ' some author ' and id<100; //delete data with the author field equal to ' an author ' and ID less than 100.

Modify (update) a record
    • UPDATE table_name SET Field 1 = new value 1, field 2 = new value 2 [WHERE condition];
    • Example: Update news set title= ' new title ', content= ' new content ' where id=3;

Query Records
    • SELECT Field 1, Field 2 from table_name [WHERE condition] [order by sort] [limit limited output (paging)];
    • SELECT * from news; //To query all the data in all columns, it is not recommended when there is a lot of data.
    • Select Id,title from news where id<100 or hits<50; //The data with ID less than 100 or CTR less than 50 is queried, and only the ID and Title columns are displayed.
    • Select Id,title from news where id<100 or hits<50 the order by ID DESC; //In descending order of ID, if ascending: order by ID, or later with ASC
    • Select Id,title from news where ID between and the order by ID of limit 0,10; //Query ID data from 10 to 40, in ascending order, output 10 data from line No. 0.

My PHP tour--sql 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.