TAILIEUCHUNG - SQL VISUAL QUICKSTART GUIDE- P33

SQL VISUAL QUICKSTART GUIDE- P33:SQL (pronounced es-kyoo-el) is the standard programming language for creating, updating, and retrieving information that is stored in databases. With SQL, you can turn your ordinary questions (“Where do our customers live?”) into statements that your database system can understand (SELECT DISTINCT city, state FROM customers;) | Chapter 8 Testing Existence with EXISTS Although I use SELECT COUNT in some of the DBMS-specific subqueries in the DBMS Tip in this section you should be wary of using an aggregate function in a subquery s SELECT clause. The existence test in Listing for example always is true because COUNT always will return a row with the value zero here . I could argue that the result Figure is flawed logically because no publisher ID XXX exists. To run Listings and in Microsoft Access change SELECT to SELECT 1. Additionally in Listing add the clause FROM authors to the outer query and in Listing add the clause FROM title_authors to the outer query. To run Listings and in Oracle add the clause FROM DUAL to the outer query see the DBMS Tip in Creating Derived Columns in Chapter 5. To run Listings and in DB2 change SELECT to SELECT 1. Additionally in Listings and add the clause FROM to the outer query see the DBMS Tip in Creating Derived Columns in Chapter 5. For example change Listing to SELECT DISTINCT Yes AS Duplicates FROM WHERE EXISTS SELECT 1 FROM authors GROUP BY au_id HAVING COUNT 1 In MySQL to run Listing add the clause FROM authors to the outer query and in Listing add the clause FROM title_authors to the outer query. MySQL and earlier don t support subqueries see the DBMS Tip in Understanding Subqueries earlier in this chapter. To run Listings and in PostgreSQL change SELECT to SELECT 1. Listing Be careful when using aggregate functions in a subquery SELECT clause. See Figure for the result. SELECT pub_id FROM publishers WHERE EXISTS SELECT COUNT FROM titles Listing WHERE pub_id XXX pub_id P01 P02 P03 P04 Figure The result of Listing . 300 Subqueries Listing These six queries are equivalent semantically they all list the authors who have written or cowritten at least one book. See Figure for the result. .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.