Restricted query and sorting display (Chapter Summary), Chapter Summary

Source: Internet
Author: User

Restricted query and sorting display (Chapter Summary), Chapter Summary
1. Standard data query syntax.

SELECT [DISTINCT] * | column [AS] [alias], column [AS] [alias],...
FROM table name [alias]
[WHERE condition (s)]
[Order by sorting field [ASC | DESC] [, sorting field [ASC | DESC]...];


2. The execution sequence of multiple statements is FROM, WHERE, SELECT, and order by. The order by statements are always placed in the final execution.


3. When using a restricted query, several conditions described are relational operations, logical operations, BETWEEN... AND, LIKE, IN, and null.


4. The order by clause can sort the query results. The order by clause must unmount the end of all query statements.
Sorting of SQL queries

Select * from table where field in (x1, x2, x3, x4......) order by field ASC/DESC
In this example, the sorting field is the field in the index condition, ASC is in ascending order, and DESC is in descending order. The sorting in this example is X1, X2, X3, but X1 may have a lot of data, if sorting is performed within X1, add the second sorting.
Select * from table where field in (x1, x2, x3, x4......) order by field ASC/DESC, Field 2 ASC/DESC
This expression is sorted by Field 2 based on the order of X1 and X2!

I don't understand how multi-data, X1, X2, and so on contain multiple records, so you don't want to use Group?

Let's take a look at the use of group by. You can limit the grouping conditions. The keyword is having. The method class where is used, but it is different from where!

SQL query statement: Random, sorted, and limit the number of repetitions of a column

SELECT a. name, a. class FROM student AS
WHERE a. name IN (select top 5 name FROM student WHERE class = a. class)
Order by class

Oh. Sorry, please try the following methods.

SELECT a. name, a. class FROM student AS
WHERE a. name IN (select top 5 name FROM student WHERE class = a. class order by class DESC/ASC, UUID () DESC/ASC limit 0, 5)
Order by class

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.