zoukankan      html  css  js  c++  java
  • Combine Two Tables

    Table: Person
    
    +-------------+---------+
    | Column Name | Type    |
    +-------------+---------+
    | PersonId    | int     |
    | FirstName   | varchar |
    | LastName    | varchar |
    +-------------+---------+
    PersonId is the primary key column for this table.
    Table: Address
    
    +-------------+---------+
    | Column Name | Type    |
    +-------------+---------+
    | AddressId   | int     |
    | PersonId    | int     |
    | City        | varchar |
    | State       | varchar |
    +-------------+---------+
    AddressId is the primary key column for this table.
    
    Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
    
    FirstName, LastName, City, State
    Select Person.FirstName,Person.LastName,Address.City,Address.State
    from Person LEFT OUTER JOIN Address on Person.PersonId = Address.PersonId

    连接类型        定义
    内连接        只连接匹配的行
    左外连接        包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行
    右外连接        包含右边表的全部行(不管左边的表中是否存在与它们匹配的行),以及左边表中全部匹配的行
    全外连接        包含左、右两个表的全部行,不管另外一边的表中是否存在与它们匹配的行。
    (H)(theta)连接        使用等值以外的条件来匹配左、右两个表中的行
    交叉连接        生成笛卡尔积-它不使用任何匹配或者选取条件,而是直接将一个数据源中的每个行与另一个数据源的每个行都一一匹配

  • 相关阅读:
    VS 2008 和 .NET 3.5 Beta 2 发布了
    搭建.NET 3.0环境
    Expression Studio和Silverlight学习资源、安装问题汇总
    Discuz! NT官方社区
    VS2005中ajax安装指南[转]
    IT人 不要一辈子靠技术生存(转)
    Discuz!NT2.5发布 正式版同步开源
    VS2005下开发Silverlight 1.1翻译加补充
    自动化测试案例
    [原]JavaScript必备知识系列开篇
  • 原文地址:https://www.cnblogs.com/hixin/p/4797989.html
Copyright © 2011-2022 走看看