交叉连接
- 语法
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)`