Home  >  Article  >  Database  >  MySQLJOINUSING()用法_MySQL

MySQLJOINUSING()用法_MySQL

PHP中文网
PHP中文网Original
2016-05-27 14:12:40975browse

MySQLJOINUSING()用法_MySQL

1 using()用于两张表的join查询,要求using()指定的列在两个表中均存在,并使用之用于join的条件。  示例:

 select a.*, b.* from a left join b using(colA);

等同于:

select a.*, b.* from a left join b on a.colA = b.colA;

2 多表查询就使用多个这样的join。 示例:

select a.*, b.* from a left join b using(colA) left join c using(colB);

要求colA在a, b中均存在,colB在a, c表中均存在。


总之,using() 只是join中指定连接条件的简写,在简单的连接中常用。在列名称不同时或连接条件复杂时就无法用了,使用 a left join b on ... 是更常见的做法。

以上就是MySQLJOINUSING()用法_MySQL的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn