Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
In a normalized database, the data to be viewed can be stored in multiple tables. When you need to view data from related tables together, you can query the data by joining the tables with the help of common attributes. You can also use subqueries where the result of a query is used as an input for the condition of another query. This chapter discusses how to query data from multiple tables by applying various types of joins, such as an inner join, outer join, cross join, equi join, or self join. Further, it explains how to use subqueries | Querying Data by Using Joins and Subqueries In a normalized database the data to be viewed can be stored in multiple tables. When you need to view data from related tables together you can query the data by joining the tables with the help of common attributes. You can also use subqueries where the result of a query is used as an input for the condition of another query. This chapter discusses how to query data from multiple tables by applying various types of joins such as an inner join outer join cross join equi join or self join. Further it explains how to use subqueries. Objectives In this chapter you will learn to fl Query data by using joins fl Query data by using subqueries Chapter 3 Querying Data by Using Joins As a database developer you may need to retrieve data from more than one table together as a part of a single result set. In such a case different columns in the result set can obtain data from different tables. To retrieve data from multiple tables the SQL Server allows you to apply joins. Joins allow you to view data from related tables in a single result set. You can join more than one table based on a common attribute. Depending on the requirements to view data from multiple tables you can apply different types of joins such as inner join outer join cross join equi join or self join. Using an Inner Join An inner join retrieves records from multiple tables by using a comparison operator on a common column. When an inner join is applied only rows with values satisfying the join condition in the common column are displayed. Rows in both tables that do not satisfy the join condition are not displayed. A join is implemented by using the SELECT statement where the SELECT list contains the name of the columns to be retrieved from the tables. The FROM clause contains the names of the tables from which combined data is to be retrieved. The WHERE clause specifies the condition with a comparison operator based on which the tables will be joined. The syntax