MySQL Common query statements

Source: Internet
Author: User
Tags name database

Basic statement

1. Mysql-u Root-p Database connection

2. Create databases database name database

3. Drop DATABASE Database name

Query statements

4.SELECT * from table name query all data in table

5. SELECT Idcard,name

From student conditional query,


From student query to duplicate value output only once


From student

WHERE idcard=1; Query student information for Idcard 1


From student

WHERE name= "TOM" and age=18; The query name is Tom and the age is 18


From student

WHERE name= "T" OR age=18; The query with the name T or the age of 18 satisfies one condition.

10. SELECT Idcard,name,age

From student

ORDER by age; Search by age in ascending order

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

12,UPDATE student SET gender = 0; Update data for a column in a table

13.UPDATE student SET gender = 0

WHERE idcard=1; Update data for a column in a row in a table


From student

WHERE Idcard = 5; Delete a row with a idcard of 5

15. SELECT *

From student

WHERE addr like "% lake"; Query the address with the lake, all output to

16. SELECT *

From student

WHERE Idcard in (1,2,4,7); Query all data for Idcard 1, 2, 4, 7

17. SELECT Idcard as Id,name,age,gender,addr

From student Modify the alias of Idcard to show the ID

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; Find information for students who are idcard to 1

19. SELECT Student.idcard

From student


SELECT mid_stu_course.course_id

From Mid_stu_course; Query results and merge result sets

This article is from the "Java" blog, so be sure to keep this source

MySQL Common query statements

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: 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.