คืนค่าการตั้งค่าทั้งหมด
คุณแน่ใจว่าต้องการคืนค่าการตั้งค่าทั้งหมด ?
ลำดับตอนที่ #3 : SQL I - Processing the Results
Ordering
Rows
ORDER
BY
To put rows in order, you can use ORDER BY in SQL. You can
also choose a specific column to use order the rows by, as shown in the example
below. You must also specify how the rows should be ordered at the end.
Ascending
& Descending Order
ORDER BY requires a method for ordering, either
"ascending" or "descending". Ascending will put the
smallest values first in the order. Descending will put the largest values
first. In SQL code, ASC
is used for "ascending" and DESC for "descending".
By putting ORDER BY at the end of an SQL
statement, the results can be put neatly in order, as shown in the example
below.
Since ORDER BY is used at the end of an SQL
statement, it can be used in combination with a WHERE clause, as shown below.
Getting
Only the Needed Rows
LIMIT
To set a specific "maximum number of
results", you can use LIMIT.
See how it works in the example below.
Just like ORDER BY, LIMIT comes at the end of an SQL statement.
So, you can use it to restrict the number of results.
Furthermore, LIMIT can be used in combination with
a WHERE clause, just as with ORDER BY.
Lesson
Review
Applying
What You've Learned
【Supplementary】
Combining ORDER BY with LIMIT
Both ORDER BY and LIMIT come at the end of an SQL
statement, but it is possible to use them together in the same statement. However,
when using them in combination, LIMIT
must come at the very end. Below is an example demonstrating how to get
the only the 5 highest prices.
ความคิดเห็น