0

A restaurant provides wine pairings for most food items on its menu. The structure of two of the tables containing this information is shown below

enter image description here

Join these two tables by their id columns to find the country that the recommended wine is produced in. Here is the code I have tried:

SELECT country, item
FROM regions
INNER JOIN pairing
    regions.id = pairing.id
ORDER BY item
LIMIT 5;

But the compiler gives the solution as:

SELECT country, item
    FROM regions
    INNER JOIN pairing
        USING(id)
    ORDER BY item
    LIMIT 5;

OUTPUT:

country item
France caviar
Italy curry
Italy grilled vegetables
Argentina lamb
Germany roast duck

Doubt:

I want to clear if there is any difference bwtween USING and equal statement on id or they are same?

Sadaf Saleem
  • 11
  • 1
  • 3
  • 2
    At least in case of PostgreSQL [it's exactly the same](https://stackoverflow.com/a/30477122/2158271). – haba713 Sep 20 '22 at 13:53
  • Yes there is a difference in syntax: But an inner join or using if defined using the same keys will produce the same results. Look the execution plan of both to see how the compiler interprets both statements. the using is just short hand when you have same named keys. – xQbert Sep 20 '22 at 13:56
  • It's a short cut if (and only if) the column names in both tables are identical. I don't know if it's ansi compliant, and I don't think all RDBMSs support it. – Andrew Sep 20 '22 at 13:58
  • Asked and answered previously: https://stackoverflow.com/questions/5654278/sql-join-is-there-a-difference-between-using-on-or-where – xQbert Sep 20 '22 at 13:59
  • That would work in oracle as well, but I would rather use the regions.id = pairing.id version. – VLOOKUP Sep 20 '22 at 15:04

0 Answers0