PHP Key 3---Simple query, add and revise

Source: Internet
Author: User

1, the most simple query
SELECT * from Car;
2. Query the specified column
Select Name,oil,powers from Car;
3, change the name of the listed names
Select name as ' car name ', oil as ' fuel quantity ', powers as ' power ' from car;
4. Search by condition
Select Name,oil,powers from car where oil = 8.7;
5. Multi-Criteria Query
Select name oil,powers from car where oil = 8.7 or powers = 160;

Select name oil,powers from car where oil = 8.7 and powers = 160;
6. Scope Query
SELECT * from car where price>=40 and price<=60;

SELECT * from car where price between and 60;
7. Discrete query
SELECT * from car where powers = Powers = or powers = 170;

SELECT * from car where powers in (130,150,170);

SELECT * from car where powers not in (130,150,170);

8. Fuzzy Query
SELECT * from car where name like '% BMW% '; % number is all characters
SELECT * from car where name like ' _ BMW '; _ Number is a character
9. Sort query ASC Ascending desc Descending order Sort the result set
SELECT * FROM car order by oil ASC;

SELECT * FROM car order by oil desc;

10, to repeat the query distinct
Select distinct brand from car;
11, paging query
SELECT * FROM Car limit 10, 5; The first number indicates the number of skipped bars, and the second number indicates the number of bars to show after the jump.

n represents the number of pages, and m indicates the numbers of bars displayed per page

Limit (n-1) *m,m;
12. Aggregate function Query
Count (column name) total number of meanings
SUM (column name) meaning of sum
AVG (column name) mean meaning
Max (column name) min (column name)

Select COUNT (*) from car;
Select SUM (price) from car;
Select AVG (price) from car;
Select Max (price) from car;
Select min (price) from car;

=========================================================================================

Delete and change

1. Adding data from a table

INSERT into car values (', ', ', ', ');

Insert INTO car (field 1, value 1) VALUES (field 2, value 2);

Insert into car set character 1, value 1 vables (character 2, value 2);

2. Modify table Data

Update car SET field 1 = value where field 2 (To see field type) = value 2

3. Delete table data

Delete from table name where field 1 = value 1

PHP Key 3---Simple query, add and revise

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.