-2

why did they in the below query, in the inner join section wrote USING not on?

SELECT
   COALESCE(department_name, '-') department,
   COALESCE(job_title,'-') job,
   COUNT(*) ,
   SUM(salary) salary
FROM
   employees
INNER JOIN departments USING (department_id)
INNER JOIN jobs USING (job_id)
GROUP BY
   CUBE(department_name,job_title)
ORDER BY
   department_name ASC NULLS LAST;
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

USING clause

  • The USING clause specifies which columns to test for equality when two tables are joined. It can be used instead of an ON clause in the JOIN operations that have an explicit join clause.

    The columns listed in the USING clause must be present in both of the two tables being joined.

    The USING clause will be transformed to an ON clause that checks for equality between the named columns in the two tables.

USING Clause is used to match only one column when more than one column matches.

syntax and example:

USING Keyword vs ON clause - MYSQL

  • ok, thanks. may i ask why did we add (=) in the subquery, in the following query: SELECT employee_id, first_name, last_name, salary, department_id FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id) ORDER BY department_id , first_name , last_name; – Mariam Mohammed Aug 15 '22 at 15:48