Get the App
SLTechnology News&Howtos  ›  Database  › 

Single table query operation of database

Shulou Source: shulou.com Published: 2022-06-01 14:31:00 10月03日 Update

Single table query operation of the database? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

A single table query refers to a query that performs data in a table, and its execution order is "from- > where- > group by- > having- > distinct- > order by- > limit- > select".

In database operations, a single table query is a query of data in a table, and its syntax is as follows:

Select distinct field 1, field 2... From table name filter condition before where grouping group by grouping field filter condition order by sort field after having grouping number of entries displayed by limit

Syntax is a kind of order, but its execution order is not from the syntax order, but such an order.

From--- > where--- > group by--- > having-- > distinct--- > order by--- > limit--- > select

As for why such an order of execution, I will not say, and I do not have the confidence to say clearly. If the rookie only needs to remember this execution order, if you have to get to the bottom of it, you can go to google.

Before we look at the single table query, let's first create an employee table:

Emp form: employee id id int name emp_name varchar gender sex enum age age int entry date hire_date date job post varchar job description post_comment varchar salary Salary double office office int department code depart_id int

Build a table:

Create table emp (id int not null unique auto_increment,name varchar (20) not null,sex enum ('male','female') not null default' male', age int (3) unsigned not null default 28legendary date date not null,post varchar (50), post_comment varchar (100), salary double (15Ling 2), office int, depart_id int)

Insert data:

Insert into emp (name,sex,age,hire_date,post,salary,office,depart_id) values ('niange','male',23,'20170301','manager',15000,401,1), (' monicx','male',23,'20150302','teacher',16000,401,1), ('wupeiqi','male',25,'20130305','teacher',8300,401,1), (' yuanhao','male',34,'20140701','teacher',3500,401,1), ('anny','female',48,'20150311') 'sale',3000.13,402,2), (' monke','female',38,'20101101','sale',2000.35,402,2), ('sandy','female',18,'20110312','sale',1000.37,402,2), (' chermy','female',18,'20130311','operation',19000,403,3), ('bailes','male',18,'20150411','operation',18000,403,3), (' omg','female',18,'20140512','operation',17000,403,3)

Where conditional filtering

You can use the following in where sentences:

1. Comparison operators: >, =,

Tags: Employee query grouping position field salary department salary order data name syntax highest condition information content function name letter that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Shulou Tech Info macOS Shulou Technology