Home  >  Article  >  Database  >  How to use JOIN USING in sql to simplify JOIN ON examples

How to use JOIN USING in sql to simplify JOIN ON examples

黄舟
黄舟Original
2017-09-08 13:48:211880browse

In the join SQL statement in Mysql, the syntax format of the ON clause is: table1.column_name = table2.column_name.

When the schema design adopts the same naming style for the columns of the joined table, the USING syntax can be used to simplify the ON syntax, with the format: USING(column_name).

For example:


[sql]
SELECT f.color, c.is_primary, c.is_dark, c.is_rainbow  
FROM flags f    www.2cto.com  
INNER JOIN color c ON f.color = c.color  
WHERE f.country = 'China';

is equivalent to


[sql]
SELECT f.color, c.is_primary, c.is_dark, c.is_rainbow  
FROM flags f  
INNER JOIN color c USING(color)  
WHERE f.country = 'China';

The above is the detailed content of How to use JOIN USING in sql to simplify JOIN ON examples. For more information, please follow other related articles on the PHP Chinese website!

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