This SQL statement is executed to query the total attendance records of all employees for the current month. It takes 2.3 seconds to display all the data.
String SQL = "select userid, orgid," + subquery, slow performance, not applicable"(Select username from t_acl_userinfo where userid = T. userid) username," +"(Select count (state) from t_chk_manage where userid = T. userid and state = '01'" + sqlappend +
Use connection (join) instead of subquery (sub-queries)MySQL supports SQL subquery starting from 4.1. This technique can use the SELECT statement to create a single-column query result, and then use the result as a filter for another query. For example, if we want to delete a customer who does not have any orders in th
Index
Understand the related tables. FOREIGN key
JOIN and maintain referential integrity
For some suggestions on joins, subquery VS. Linked table Query
I found that there is a tutorial in the MySQL documentation, but the concept does not seem to mention, just tell you how (statement), did not tell you the cause and consequences (principle).
Mysql common query: groupby, left join, subquery, havingwhere I went to two relatively popular Internet companies for an interview a few days ago. I encountered a problem in SQL, first, let's take a brief look at score1 and groupby in the two-dimensional table for grouping by a certain dimension. For example: calculate the total score of each student, SELECTstude
Mysql common query: groupby, left join, subquery, havingwhere I went to two relatively popular Internet companies for an interview a few days ago and encountered problems in SQL. well, unfortunately, I 'd like to sort it out first.
Score
1. use group
Group by dimension
For example:
Calculate the total score of each student.
SELECT student, SUM (score) FRO
Tags: notation col from Port ACK member Div size BSPnot much to say directly on the statement SELECT a.ID, A.thumbnail, A. NAME, A.marketprice, A.memberprice, A.personname, A. STATUS, A.recieveorderdate, A.tracknumber, A.contact, A.reportsenddate, B. Tracknumber, A. Reportdownloadpath from ( SELECT Od.id, Ps.thumbnail, PS. NAME, Od.marketprice, Od.memberprice, Od.personname, od. STATUS, Od.recieveorderdate, Ol.tracknumber, Ol.contact, Od.reportsenddate, Od.reportsendorderlogisticid, Od.report
Ask! When mysql returns a fixed result set, whether the result set is repeatedly executed, for example, 1: selectt. *, (selectcount (1) fromtable01) fromtable01t; for example, 2: selectt. *, (selectcount (1) fromtable01t2wheret2. keyt1.key) fromtable01t1; -- Nested subqueries like this will be executed repeatedly. Q: In the subquery traversal process in example 1 above, there are fixed result sets. Will the
This article mainly introduces the basic use of join statements in MySQL and the impact of fields on performance. It provides an example to observe the performance differences caused by the encoding of different field character sets used by join, for more information, see
Ba
There is such a requirement:
There are multiple tables on the server, and they all have associated key Content-id.
The previous practice was to:
The front end sends an AJAX request, back-end MySQL according to Content-id, will be a number of tables to do join query, PHP output JSON, and then the front end of the JSON parsing rendering.
But some colleagues say this is too much to consume
Tags: sts post ecshop direct 4 line query optimization exist 0.00 explain In -type sub-query leads to traps: (Sweep less rows, not temporary tables, do not sort files quickly) title: In the Ecshop Mall table, query 6th items, (note, number 6th is a large column) the most intuitive: MySQL> SelectGoods_id,cat_id,goods_name fromGoodswherecat_idinch(Selectcat_id fromCategorywhereparent_id=6); Misunderstanding: Give us the feeling is, first found in the in
b.name = A.name
Left Join C on c.name = B.name and c.status>1
Left Join D on d.id = C.id and D.status=1
As can be seen from the example above, the condition of On is met as much as possible, and the condition of where is less used. In terms of performance, the second is obviously more time-saving.
(2). Note the difference between the ON clause and
set of students in A school and B represents A set of all courses in the school, cartesian products of A and B represent all possible course selections.
Mysql> select * from A cross join B; + ---- + ----------- + ---- + ------------- + | id | name | + ---- + ----------- + ---- + ------------- + | 1 | Pirate | 1 | Rutabaga | 2 | Monkey | 1 | Rutabaga | 3 | Ninja | 1 | Rutabaga | 4 | Spaghetti | 1 | Rutabag
complete. It retrieves the filter from the data that is produced during the matching phase.
So we should note that when using the left (right) join, it is important to give as many matches as possible to satisfy the condition and reduce the where execution. such as:PASSselect * from Ainner join B on B.name = A.nameleft join C on C.name = B.nameleft
|+----+--------+------+--------+-------+4 rows in Set (0.00 sec) mysql> select * FROM pro Duct left JOIN product_details on (product.id = product_details.id) WHERE product_details.id=2;+----+--------+----+--------+-------+ | ID | amount | id | weight | exist |+----+--------+----+--------+-------+| 2 | 200 | 2 | 22 | 0 |+----+--------+----+--------+-------+1 row in Set (0.01 sec)
From the
Original: Mysql join syntax parsing and performance analysisA Join Syntax OverviewJoins are used for the connection between fields in multiple tables, with the following syntax:... FROM table1 INNER|LEFT|RIGHT JOIN table2 ON conditionaTable1: Left table; table2: Right table.
Mysql: 21 best practices for performance optimization 5 [use and index equivalent columns when joining a table] bitsCN.com
When you Join a table, use a column of equivalent type and index it.
If your application has many JOIN queries, you should confirm that the Join field
... INNER JOIN ... The ON statement is as follows:
SELECT article.aid,article.title,user.username from article INNER JOIN user on article.uid = User.uid
Return query results as follows:
For INNER JOIN, equate to the following SQL statement:
SELECT article.aid,article.title,user.username from article,user WHERE article.uid = User.uid
retrieval. SQL, select * from A is not recommended Left Join B on a.mobile = B.mobile Left Join C on a.name = C.name where A.status = 1 and c.status = 1 Recommended SQL-select * from A Left Join B on a.mobile = b.mobile and a.status = 1 Left Join C on a.name = c.name and c.status = 1 Try to satisfy the on condition, a
is produced during the matching phase.
So we should note that when using the left (right) join, it is important to give as many matches as possible to satisfy the condition and reduce the where execution. such as:PASSselect * from Ainner join B on B.name = A.nameleft join C on C.name = B.nameleft join D on D.id
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.