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