MySQL queries the in operation. The query results are displayed in the in set order.
Copy codeThe Code is as follows: select * from test where id in (, 5) order by find_in_set (id, '3 ');
Select * from test where id in (3, 1, 5) order by substring_index ('3, 1, 2 ', id, 1 )
MySQL queries the in operation. The query results are displayed in the in set order. Copy codeThe Code is as follows:Select * from test where id in (3, 1, 5) order by find_in_set (id, '3, 1, 5 ');Select * from test where id in (3, 1, 5) order by substring_index ('3, 1, 2 ',
generate 1000 pieces of data in the t_team table and 100000 pieces of data in the t_people table. (Stored procedure is at the end of this article)Execute the preceding SQL statement several times, which takes about 3 seconds.
Then compare the two statements:1. Remove the order by clause: select * from t_people p left join t_team t on p. team_id = t. id limit10; [Statement ②]It takes 0.00 seconds.
2. Use order
stored procedure to generate 1000 data in the T_team table and 100,000 data in the T_people table. (Stored procedure at the end of this article)
Execute the above SQL statement several times, taking about 3 seconds.
Another two statements to compare:
1. Remove the ORDER BY clause: SELECT * from T_people p LEFT join T_team T on P.team_id=t.id limit10; [Statement ②]
Takes 0.00 seconds, negligible.
2. Or use order
MySQL Query in operation, query results in set order display
Copy Code code as follows:
SELECT * from test where ID into (3,1,5) Order by Find_in_set (ID, ' 3,1,5 ');
SELECT * from test where ID into (3,1,5) Order
MySQL Query in operation, the query results are displayed in the order of in collection
Copy CodeThe code is as follows:SELECT * from test where ID in (3,1,5) Order by Find_in_set (ID, ' 3,1,5 ');SELECT * from test where ID in (3,1,5)
1000 pieces of data in the t_team table and 100000 pieces of data in the t_people table. (Stored procedure is at the end of this article)Execute the preceding SQL statement several times, which takes about 3 seconds.Then compare the two statements:1. Remove the order by clause: select * from t_people p left join t_team t on p. team_id = t. id limit10; [Statement ②]It takes 0.00 seconds.2. Use order by, but
Label:MySQL random query: MySQL Order by Rand () efficiency problem has always been a developer's frequently asked questions, we are not DBA, not so cow B, can only slowly study, recently due to project issues, need to probably study the MySQL random extraction implementation method To randomly extract a record from th
The occasional sight of ... Maybe someone would have noticed, but I didn't know it before.Sql:select * FROM table where ID in (3,6,9,1,2,5,8,7);After such a situation is taken out, in fact, the ID or by 1,2,3,4,5,6,7,8,9, sorted, but if we really want to press in the order of the inside of what to do? Can SQL be completed? Do you need to take it back and then foreach it? Actually, that's the way MySQL is.Sq
Label:Turn from: Http://blog.itpub.net/29254281/viewspace-2086198/MySQL Order sub-database sub-table multi-dimensional queryMySQL Sub-database sub-table, generally can only follow one dimension of the query.Take the order form example and divide it into 64 databases according to the user ID mod 64.Query the user's dime
Because the records of the database may need to be reordered. In this article, I will talk about improving the order BY statement query efficiency of two ideas for your reference.
In the MySQL database, the ORDER BY statement is used more frequently. However, it is well known that the use of this statement tends to d
Because the database records may need to be reordered. In this article, I will talk about two ideas to improve the query efficiency of Order By statements for your reference.
In MySQL databases, Order by statements are frequently used. However, it is well known that when using this statement, data
Tags: values having group SQL query order REM value repeat cachePython 3 MySQL SQL logical query statement execution order one, the definition order of the SELECT statement keywordSELECT DISTINCT
_number>Second, the executi
clause is used with the ORDER BY clause. The MySQL database limit supports the following forms of selection: LIMIT N, M Indicates that the M record is selected starting with the nth record. And many developers like to use this statement to solve paging problems. For small data, using the LIMIT clause has no problem, and when the amount of data is very large, the use LIMIT n, m is very inefficient. Because
from test where name=‘mark‘)union all(
select id,name,group_id from test where name=‘jason‘)order by group_id; the parentheses of a child statement are not necessary, but the syntax does not look clear and is prone to ambiguity. Note:Specifies that the number of fields retrieved by multiple SELECT statements must be the same.The data types should be consistent, and if MySQL field properties are inconsiste
Therefore, there are often such errors
Copy Code code as follows:
SELECT * FROM [IND] where indid>10UnionSELECT * FROM [IND] where indid
So far, there has been no question of
After that, maybe someone will use a similar query.
Copy Code code as follows:
SELECT * FROM [IND] where indid>10 order BY indid DescUnionSELECT * FROM [IND] where indid
At this point there is
column after a query
-- Check the "name" and "Year of birth" columns
for all students Select as name, as from student;
Single-Condition Query
-- the search position is the record of salesman;
Select * from where job='salesman'
Multi-Criteria Query
--Query department records in
Therefore, such errors often occur.Copy codeThe Code is as follows:Select * from [IND] where INDID> 10UnionSelect * from [IND] where INDID So far, no questions have been asked
Later, someone may use similar queries.Copy codeThe Code is as follows:Select * from [IND] where INDID> 10 order by INDID descUnionSelect * from [IND] where INDID The database reports an error. The problem lies in order.
Why? Can UNIO
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.