zoukankan      html  css  js  c++  java
  • sql join

    SQL JOIN

    A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

    Let's look at a selection from the "Orders" table:

    OrderIDCustomerIDOrderDate
    10308 2 1996-09-18
    10309 37 1996-09-19
    10310 77 1996-09-20

    Then, look at a selection from the "Customers" table:

    CustomerIDCustomerNameContactNameCountry
    1 Alfreds Futterkiste Maria Anders Germany
    2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico
    3 Antonio Moreno Taquería Antonio Moreno Mexico

    Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.

    Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables:

    Example

    SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
    FROM Orders
    INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
    Try it Yourself »

    and it will produce something like this:

    OrderIDCustomerNameOrderDate
    10308 Ana Trujillo Emparedados y helados 9/18/1996
    10365 Antonio Moreno Taquería 11/27/1996
    10383 Around the Horn 12/16/1996
    10355 Around the Horn 11/15/1996
    10278 Berglunds snabbköp 8/12/1996

    Different Types of SQL JOINs

    Here are the different types of the JOINs in SQL:

    • (INNER) JOIN: Returns records that have matching values in both tables
    • LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
    • RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
    • FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

       

  • 相关阅读:
    SpringBoot返回json和xml
    Spring boot 集成MQ
    Spring boot freemarker 配置
    Spring boot 自定义注解标签记录系统访问日志
    RIDE对应驱动下载
    在线修改pdf识别图片
    记公司食堂收厨余垃圾的人
    [Ruby]使用Ruby抓取网页及加工处理
    [转载]SCSS 和 SASS 和 HAML 和CoffeeScript
    [ACM]反复平方法的两种写法
  • 原文地址:https://www.cnblogs.com/oxspirt/p/11545955.html
Copyright © 2011-2022 走看看