The Language of SQL- P17

The Language of SQL- P17: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. | 66 Chapter 7 Row-Based Logic In this example only one row meets the qualification that the QuantityPurchased column be greater than 6. Although not as commonly used it s also possible to use the is greater than operator with a text column. This example SELECT FirstName LastName FROM Orders WHERE LastName K returns FirstName LastName William Smith Natalie Lopez Since the test is for last names greater than K it only brings back Smith and Lopez but not Harper. When applied to text fields the greater than and less than operators indicate selection by the alphabetic order of the values. In this case Smith and Lopez are returned since S and L are after K in the alphabet. Finally it should be noted that all of these operators can also be used with the WHEN keyword in the searched format of the CASE expression. For example a valid CASE expression might be CASE WHEN columnl valuel THEN resultl END Limiting Rows What do you do if you want to select a small subset of the rows in a table but you don t care which rows are returned Let s say that you have a table with 50 000 rows and you want to see just a few rows of data to see what it looks like. It wouldn t make sense to use the WHERE clause for this purpose since you don t care which rows are returned. The solution is to use a special keyword to specify that you want to limit how many rows are returned. This is another instance where the syntax differs among Limiting Rows 67 databases. In Microsoft SQL Server the keyword that accomplishes this task is TOP. The general format is SELECT TOP number columnlist FROM table DATABASE DIFFERENCES MySQL and Oracle MySQL uses the keyword limit rather than top. The general format is SELECT columnlist FROM table LIMIT number Oracle uses the keyword ROWNUM rather than TOP. The ROWNUM keyword needs to be specified in a WHERE clause as follows SELECT columnlist FROM table WHERE ROWNUM number In the remainder of this chapter you ll see statements using the Microsoft TOP keyword. If you re

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
184    104    9    02-07-2024
154    93    1    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.