The Language of SQL- P13

The Language of SQL- P13:Research has shown that, being pressed for time, most readers tend to skip the introduction of any book they happen to read and then proceed immediately to the first real chapter. With that fact firmly in mind, we will only cover relatively unimportant material in the introduction, such as an explanation of what you will and will not learn by reading this book. | This page intentionally left blank CHAPTER 5 Sorting Data Keywords Introduced ORDER BY ASC DESC The ability to present data in a sorted order is often essential to the task at hand. For example if you were shown a large list of customers in a random order you d find it difficult to locate any one particular customer. However if the same list were sorted alphabetically then you could quickly locate the desired customer. The idea of sorting data alphabetically applies to many situations even when the data isn t strictly alphabetic in nature. For example you may want to sort a list of orders by the order date and time to allow you to rapidly find an order taken at a particular date and time. Or you might want to sort a list of orders by the order amount to allow you to view orders from the smallest to the largest. No matter what particular form your sort takes it adds a useful way to organize your data as it is being presented to the end user. Adding a Sort Up until now data has not been returned in any particular order. When a SELECT is issued you never know which row will come first. If the query is executed from within a software program and no one ever sees the data at that point in time then it really doesn t matter. But if the data is to be immediately displayed to a user then the order of rows is often significant. A sort can be added easily to a SELECT statement by using an ORDER BY clause. 47 48 Chapter 5 Sorting Data Here s the general format for a SELECT statement with an ORDER BY clause SELECT columnlist FROM tablelist ORDER BY columnlist The ORDER BY clause is always after the FROM clause which in turn is always after the SELECT keyword. The italicized columnlist for the SELECT and ORDER BY keywords indicates that any number of columns can be listed. The columns in columnlist can be individual columns or more complex expressions. The columns specified after the SELECT and ORDER BY keywords can be entirely different columns. The italicized tablelist .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
108    188    2    02-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.