Get the App
SLTechnology News&Howtos  ›  Database  › 

Query methods of commonly used sentences in mysql

Shulou Source: shulou.com Published: 2022-06-01 20:47:04 09月11日 Update

The following content mainly brings you the query methods of commonly used sentences in mysql. The knowledge mentioned here, which is slightly different from books, is summed up by professional and technical personnel in the process of contact with users, and has a certain value of experience sharing. I hope to bring help to the majority of readers.

Basic statement

1. Mysql-u root-p database connection

2. Create a database by create databases database name

3. Delete the database by drop database database name

Query statement

4. SELECT * FROM table name queries all data in the table

5 、 SELECT idcard,name

FROM student conditional query

6 、 SELECT DISTINCT addr

Duplicate values are output only once when queried by FROM student

7. SELECT *

FROM student

WHERE idcard=1; queries student information with idcard 1

8. SELECT *

FROM student

WHERE name= "TOM" AND age=18; query name is TOM and age is 18

9. SELECT *

FROM student

WHERE name= "T" OR age=18; query name is T or age is 18 to meet a condition

10 、 SELECT idcard,name,age

FROM student

ORDER BY age; query in ascending order of age

11. INSERT INTO student VALUES (7, "MARRY", 22 # 1, "Zhejiang Shaoxing"); insert data like a table

12. UPDATE student SET gender = 0; update the data of a column in the table

13. UPDATE student SET gender = 0

WHERE idcard=1; updates the data of a row and column in a table

14 、 DELETE

FROM student

WHERE idcard = 5; delete the row with idcard 5

15. SELECT *

FROM student

WHERE addr LIKE "% Lake%"; all those with lakes in the query address are output.

16. SELECT *

FROM student

WHERE idcard IN (1, 2, 4, 7); query all data with idcard of 1, 2, 4, 7

17 、 SELECT idcard AS id,name,age,gender,addr

FROM student changed the alias of idcard to id to show it.

18, SELECT student.`name`, student.age,student.addr,course.course_name,mid_stu_course.grade

FROM student

JOIN mid_stu_course ON student.idcard=mid_stu_course.idcard

JOIN course ON mid_stu_course.course_id=course.course_id

WHERE student.idcard=1; queries the information of students with idcard 1

19 、 SELECT student.idcard

FROM student

UNION

SELECT mid_stu_course.course_id

FROM mid_stu_course; query results and merge result sets

For the above query methods about the commonly used sentences in mysql, if you have more information, you can continue to pay attention to the innovation of our industry. If you need professional answers, you can contact the pre-sales and after-sales on the official website. I hope this article can bring you some knowledge updates.

Tags: Queries data databases statements age updates commonly used methods majors information names students conditions knowledge results output different below books people Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Shulou Information Shulou Technology macOS