MySQL statement notes

Source: Internet
Author: User

CREATE TABLE' Player ' (' ID ' )int( One) not NULLauto_increment, ' name 'Char( -) not NULL DEFAULT "'COMMENT'Site name', ' area 'varchar(255) not NULL DEFAULT "', ' Alexa 'int( One) not NULL DEFAULT '0'COMMENT'Alexa Rankings', ' team 'Char(Ten) not NULL DEFAULT "'COMMENT'National',  PRIMARY KEY(' id ')) ENGINE=InnoDB auto_increment=Ten DEFAULTCHARSET=UTF8;INSERT  into' Player 'VALUES('1','Leonard','San Antonio, USA',' the','Spurs'), ('2','Curry','United States Jinzhou','94','Warriors'), ('3','Durant','United States Jinzhou',' the','Warriors'), ('4','James','Cleveland, USA',' the','Knights'), ('5','Lillard','United States Oakland',' the','Pioneering person');

First, the header is created, and then the data is inserted

Table and library concept, (the database is equivalent to a file bag, there are many table tables)
Show databases;//View Gallery
Use map;//using a library
Show table;//all tables in the gallery
SELECT * from player;//table data in the Search table msg

The above learning in the database learndb, the inside injected with SQL script
Basic concepts
1. The database is a software for managing data
There are a lot of 2.mysql clients (MYSQL.EXE,PHPMYADMIN,NAVICAT)
Mysql.exe is a purely command-line client
Basic operations:
The most basic:
show databases; View Library
Use test; Select Library
Show tables; View the table of the library
SELECT * from player; retrieve all columns

A little to remember:
Retrieving data:
1. Retrieve all columns select * FROM Products;
2. Retrieving different values select DISTINCT vend_id from the products;
3. Search limit Results Select Prod_name from the products limit 5;

Sort the retrieved data:
1. Sort data Select Prod_name from the products order by Prod_name;
2. Sorting multiple columns Select Prod_id,prod_price,prod_name from the products order by Prod_price,prod_name;
3. Sort the column position select Prod_id,prod_price,prod_name from the products order by 2, 3;
4. Descending order Select Prod_id,prod_price,prod_name from the products order by Prod_price DESC;


Filter data:
1. Using the WHERE clause
Select Prod_name,prod_price from Products where prod_price=3.49;
The following is the operator of the WHERE clause:
(1) Check single value: Where prod_price<=10;
(2) Mismatch check: SELECT vend_id, prod_name from Products WHERE vend_id <> ' DLL01 ';
(3) Range value check: SELECT prod_name, prod_price from Products WHERE Prod_price between 5 and 10;
(4) Null value check:
Advanced filtering:

MySQL statement notes

Related Article

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.