zoukankan      html  css  js  c++  java
  • MySQL数据库之多表查询cross join交叉连接

    交叉连接

    • 语法
      • select * from 表1 cross join 表2 on ...
      • 交叉连接如果没有连接条件返回笛卡尔积
      • 如果有连接条件和内连接是一样的
    MariaDB [sel]> select * from grades cross join resume;
    +-------+---------+------+----+-------+-----------+
    | name  | chinese | math | id | name  | skill     |
    +-------+---------+------+----+-------+-----------+
    | Sunny |      93 |   96 |  1 | Sunny | php       |
    | Sunny |      93 |   96 |  2 | Kimmy | php       |
    | Sunny |      93 |   96 |  3 | Jerry | php,mysql |
    | Jerry |      97 |   91 |  1 | Sunny | php       |
    | Jerry |      97 |   91 |  2 | Kimmy | php       |
    | Jerry |      97 |   91 |  3 | Jerry | php,mysql |
    | Marry |      95 |   94 |  1 | Sunny | php       |
    | Marry |      95 |   94 |  2 | Kimmy | php       |
    | Marry |      95 |   94 |  3 | Jerry | php,mysql |
    | Tommy |      98 |   94 |  1 | Sunny | php       |
    | Tommy |      98 |   94 |  2 | Kimmy | php       |
    | Tommy |      98 |   94 |  3 | Jerry | php,mysql |
    +-------+---------+------+----+-------+-----------+
    # `12 rows in set (0.001 sec)`
    
    • 交叉连接有连接表达式与内连接是一样的
    MariaDB [sel]> select * from grades cross join resume on grades.name=resume.name;
    +-------+---------+------+----+-------+-----------+
    | name  | chinese | math | id | name  | skill     |
    +-------+---------+------+----+-------+-----------+
    | Sunny |      93 |   96 |  1 | Sunny | php       |
    | Jerry |      97 |   91 |  3 | Jerry | php,mysql |
    +-------+---------+------+----+-------+-----------+
    # `2 rows in set (0.000 sec)`
    
  • 相关阅读:
    Alpha冲刺博客集
    Alpha冲刺——第一天
    团队项目需求分析
    结对第二次作业
    项目选题报告
    随笔2 PAT1001.A+B Format (20)
    随笔1 大一下学期自我目标
    大数
    列变位法解密--百度之星B题
    hdu1874 畅通工程续 dijkstra 最短路
  • 原文地址:https://www.cnblogs.com/SharkJiao/p/14137841.html
Copyright © 2011-2022 走看看