Possible Duplicate:
MySQL ON vs USING?
Query 1:
SELECT *
FROM users
JOIN orders ON (orders.user_id = users.user_id)
WHERE users.user_id = 1;
Query 2:
SELECT *
FROM users
JOIN orders USING (user_id)
WHERE user_id = 1;
I want to join orders and users tables to get some certain data. It works fine. My issue is since both queries output the same results set, is it the same? Which one is more efficient to be used? Which one is good for performance ? Which one is the best practise ?
The
USINGclause is something we don’t need to mention in theJOINcondition when we are retrieving data from multiple tables. When we use aUSINGclause, that particular column name should be present in both tables, and theSELECTquery will automatically join those tables using the given column name in theUSINGclause.For example, if there are two common column names in the table, then mention the desired common column name in the
USINGclause.USINGis also used while executing Dynamic SQL, like so:The
USINGclause: This allows you to specify the join key by name.The
ONclause: This syntax allows you to specify the column names for join keys in both tables.The USING clause
The ON clause