Mysql statement common query (basic article)


Some basic sql statements, recently looked at sql statements, and sql optimization, just made some summaries in the notes, not comprehensive, and I will add some in the future.


Sql basic content: 
1, select * from user query user table all

2. Select distinct user_age, user_name from user to query all the unique user_age, user_name.

3. Where to do conditional query: 
Some common operators:  
= Equal; <> not equal; <= less than or equal;> = greater than or equal to;
between and; like fuzzy query; in specifies multiple possibilities for a certain column.

4, the use priority of and and or: () not and or
SELECT * FROM Websites WHERE alexa > 15 AND (country='CN' OR country='USA');

5. The order by keyword is used to sort the result set. Ascending ASC (default) Descending DESC
SELECT column_name,column_name FROM table_name
ORDER BY column_name,column_name ASC|DESC;

6, insert into insert data into the database
insert into 表名 values (value1,value2,value3,...);
insert into 表名 (column1,column2...)values (value1,value2...);

7, update update the database
update table name set column1 = value1, column2 = value2 ... where condition.
UPDATE Websites SET alexa='5000', country='USA' WHERE name='111';

8, create database database name

9, delect from table name where condition deletes a record of a table.

Published 26 original articles · praised 0 · visits 9938

Guess you like

Origin blog.csdn.net/weixin_38246518/article/details/78691594