Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Java Database Programming Bible- P3: Welcome to Java Database Programming Bible. This book is for readers who are already familiar with Java, and who want to know more about working with databases. The JDBC Application Programming Interface has made database programming an important aspect of Java development, particularly where Web applications are concerned. | Chapter 3 SQL Basics o.Order_Date FROM ORDERS o CUSTOMERS c WHERE o.customer_number c.customer_number Note In the shorthand version the type of JOIN depends on both the order of the tables in the FROM clause and the position of the asterisk in the operator. FULL OUTER JOIN A full outer join includes all unmatched rows from both tables in the result. For example to find any orders in the Orders Table with customer numbers that do not match any entries in our Customers Table you can execute a Full Outer Join to show all the entries in both tables. Here s an example SELECT c.Last_Name c.First_Name o.Order_Date FROM Customers c FULL OUTER JOIN Orders o ON c.Customer_number o.Customer_Number The result set generated by this join is the same as the results shown in Table 3-14 since all orders have a corresponding customer. However if for some reason an order placed on 12 12 01existed in the Orders Table with no corresponding entry in the Customers Table the additional row shown at the bottom of Table 3-15 would be generated. Table 3-15 Results of FULL OUTER JOIN Last_Name First_Name Order_Date Corleone Michael NULL Corleone Fredo 12 8 01 Corleone Sonny NULL Corleone Francis 12 9 01 Corleone Vito 12 9 01 Hagen Tom NULL Adams Kay 12 10 01 Coppola Francis NULL Puzo Mario NULL NULL NULL 12 12 01 Using NOT EXISTS -99- Team-Fly Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Chapter 3 SQL Basics Now you know how to use INNER JOINS to find records from two tables with matching fields and how to use OUTER JOINS to find all records matching or nonmatching. Next consider a case in which you want to find records from one table that don t have corresponding records in another. Using the Customers and Orders Tables again find all the customers who have not placed an order. The way to do this is to find customer records with customer numbers that do not exist in the Orders Table. This is done using NOT EXISTS SELECT c.Last_Name c.First_Name AS Customer .