The MySQL order BY keyword is used to classify the data in the record.MySQL ORDER BY keyword classified by keywordThe ORDER BY keyword is used to classify the data in a record.
Copy Code code as follows:
SELECT column_name (s)
From table_name
ORDER BY co
When using MySQL sorting, you would expect to get a set of data in descending order, but using order by often gets not the desired result, so how can you use Group by and order by to get the desired data results?For example there is a reply sheet for a post, posts (ID, TID, subject, message, Dateline),ID is the autogro
Next I will use the users (Userid,username,password ...). Table (with Ibedovan Records) as an example, to explain the next several methods of efficiency problems:
The code is as follows
Copy Code
1.select * from the Users Order by rand () LIMIT 1
Execute the SQL statement, no response for a while, finally forced to manually stop execution, how to hurt people ah! Then I looked up the
true, Then the field in select must appear in group by, so it is obvious that the old new version of the problem.Official documentation here:A new function, Any_value (), is available so can used to forceMySQL to accept queries that it thinks should is rejected withOnly_full_group_by enabled.The function return value and type areThe same as the return value and type of its argument, but thefunction result is a checked for the only_full_group_by SQL mode.If you find that has only_full_group_by e
Link query and set query bitsCN.com
Connection query and set query
In the database query process, sometimes the data records in a table cannot meet the needs of developers or customers. For example, query the student's course se
"How does the Order by rand () in MySQL come into being?" Let's briefly talk about order by in MySQL today.case of several order byShangri-La CasinoAt first glance the problem seems a bit complicated, and we start with the simplest case.Use this table to illustrate: (10w row
order by default (from 1 to 9, from a to z)Use the "DESC" keyword to sort all data in descending order (from 9 to 1, from z to ):SELECT column_name (s)FROM table_nameOrder by column_name DESCMySQL Order By is classified By two columnsMost of the time, we need to classify data based on the two columns (or more columns) at the same time. When the specified number
repeated, all columns are the same (for example, the data in rows 5 and 6 in the following table is identical ).The maximum two (N) val values are grouped by name.Copy codeThe Code is as follows:/*The data is as follows:Name val memoA 2 a2 (the second value of)A 1 a1 -- the first value ofA 1 a1 -- the first value ofA 3 a3: The third value ofA 3 a3: The third value ofB 1 b1 -- the first value of BB 3 b3: The third value of BB 2 b2b2b2b2B 4 b4b4B 5 b5b5b5b5b5*/ Appendix: Studies on
Create the mysql_order_by_test data table according to the following table structure. We will use instance to tell you how to use MySQL order.
Order by uid ASC
Query data in the forward order of uid, that is, sort data in ascending orde
Using filesort caused by order by optimization by MySQL
Using filesort is generally used in the order by statement.
Using filesort does not necessarily cause mysql performance problems. However, if the number of queries is very large, sorting in mysql will still be affected.
Article Source: http://blog.csdn.net/sunrier/article/details/7572299Installation of MySQL administrator and MySQL Query browser under LinuxThe following is my first installation process (Red Hat Enterprise Linux 5)Download Http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0r12-rhel4-i386.tar.gz/from/pi
value in the Name fieldSELECT name,age from students WHERE Name is NULL;Finding data with a name field that is not a null valueSort the found data in ascending or descending order: order by Field_name {asc| DESC};ASC Ascending order (default value) desc Descending sortSELECT Name,age from students WHERE the CID is not NULL O
the XXID index:Get_quick_record_countTest_quick_select:Cost of final calculation:Estimated_records=1best_read_time=2.21Specific calculation method, you can refer to the previous blogTo this: Xpchild in the JOIN_TAB structure, relatively simple, const table type, cost=1;In the JOIN_TAB structure of Xpchild_1, Found_records=1, read_time=2.21;For a single-table query, access path is already optimal.Order of Step 4:join:Choose_join:1. If it is a const ta
Key:category
Key_len:4
Ref:const
rows:100
Extra:using where; Using index; Using temporary; Using Filesort
3. Row ***************************
Id:2
Select_type:dependent subquery
Table:i
Type:ref
Possible_keys:subcategory
Key:subcategory
Key_len:4
Ref:c.id
Rows:28
Extra:using Index
How do you not know how to analyze the MySQL statement query plan, please see the general meaning:
'sheet % ';
Null value query
mysql> select * from student where address is null;
And multi-condition query
Mysql> select * from student where name like 'Zhang % 'and birth> 1985; mysql> select * from student where name like 'Zhang % 'and birth> 1985 and id like' % 3 ';
O
MySQL's order by involves three parameters:A. sort_buffer_size sort Cache.B. Read_rnd_buffer_size the second sort cache.C. Max_length_for_sort_data The maximum sort constraint with a normal column.Let me just briefly say MySQL's sort rules. Suppose query statement select * FROM TB1 where 1 order by A; Field A does not have an index; the above three parameters are
of the entire table? (different libraries, different tables)
Add an index condition such as EXPLAIN SELECT *From ' Order2 'WHERE 1 and Create_time>0ORDER by ' Create_time ' DESC
Remember, if your table data cardinality is too small, or the distribution is not large, the MySQL query optimizer will remove the index, perform a full table scan.This automatic optimization behavior is not predictable, so wh
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.