zoukankan      html  css  js  c++  java
  • 结合两张表person和address

    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.



    为报表编写一个SQL查询,为Person表中的每个人提供以下信息,而不管这些人是否有地址:
    FirstName ,LastName,City ,State


    根据条件不管这些人是否有地址,如果用inner join 那么在地址表中,没用地址的人们将不会出现结果中。所以用左外连接。
    select p.FirstName,p.lastname,a.city,a.state from person p left join address a on p.personId = a.personId
    因为查询字段在两张表中是唯一的,所以可以省略表前缀,写成
    select FirstName ,LastName ,city ,state from person left join address on Person.personId = address.personId
  • 相关阅读:
    做接口测试最重要的知识点
    HTTP和HTTPS区别
    UVA, 686 Goldbach's Conjecture (II)
    UVA, 543 Goldbach's Conjecture
    UVA, 580 Critical Mass
    UVA, 900 Brick Wall Patterns
    UVA, 11000 Bee
    UVA, 10079 Pizza Cutting
    C++ 向量<vector>的学习
    jenkins入门
  • 原文地址:https://www.cnblogs.com/jiangshengxiang/p/8420776.html
Copyright © 2011-2022 走看看