Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Simple operation example of MySQL query statement

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This paper gives an example to illustrate the simple operation of MySQL query statement. Share with you for your reference, the details are as follows:

Query

Create databases, data tables

-- create a database create database python_test_1 charset=utf8;-- using database use python_test_1;-- students tables create table students (id int unsigned primary key auto_increment not null, name varchar (20) default', age tinyint unsigned default 0, height decimal (5 is_delete bit default 2), gender enum ('male', 'female', 'neutral', 'secret') default 'secrecy', cls_id int unsigned default 0, is_delete bit default 0) -- classes table create table classes (id int unsigned auto_increment primary key not null, name varchar (30) not null)

Prepare data

Insert data into the students table insert into students values (0meme 'Xiaoming', 18180.00pyr2 pyrrine 0), (0meme 'Xiao Yueyue', 18180.00pyrrine 2 pyrrine 1), (0meme 'Peng Yuyan', 29185.00 pyrrine 1), (0mine`Liu Dehua', 59175.00mrong 1), (0mine` 'Huang Rong', 38160.000.00 mrong 1), (0jue 'Fengjie', 28150.000.00 4pr 2penny), (0le 'Wang Zuxian', 18172.002 repar1), (0) 'Jay Chou', 36 ~ null _ recorder 1), (0 ~ ~ 'Cheng Kun', 27181.00 ~ 1), (0 ~ 'Liu Yifei', 25166.00 ~ 2), (0 ~ 'Jin Xing', 33162.00 ~ 3), (0 ~ Jingxiang, 12180.0000 ~ 2), (0 ~ Guo Jing, 12170.001), (0 ~ 'Zhou Jie', 34176.00 ~ 2) -- insert data insert into classes values (0, "python_01 period"), (0, "python_02 period") into the classes table

Query all fields

Select * from table name

Example:

Select * from students

Query the specified field

Select column 1, column 2. From table name

Example:

Select name from students

Use as to alias fields

Select id as serial number, name as name, gender as gender from students

You can alias the table through as

If it is a single table query, you can omit the select id, name, gender from students;-- table name. The field name select students.id,students.name,students.gender from students;-- can be aliased to the table via as, select. ID _ journal. Name _ journal. Gender from students as s.

Eliminate duplicate lines

Use distinct before the column after select to eliminate duplicate rows

Select distinct column 1. From table name

Example:

Select distinct gender from students

More readers who are interested in MySQL-related content can check out this site topic: "MySQL query skills Collection", "MySQL Common function Summary", "MySQL Log Operation skills Collection", "MySQL transaction Operation skills Summary", "MySQL stored procedure skills Collection" and "MySQL Database Lock related skills Summary"

It is hoped that what is described in this article will be helpful to everyone's MySQL database design.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 256

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report