0

I was studying Theta join. In join condition, we can use 'on' or 'using' for specifying common columns in two or more tables. Now how would I know If I am to use 'on' or 'using' ?

Example

Find customer names and their loan amounts (loan and borrower are two relations)

Table layout:

loan (loan_number, branch_name, amount)!
borrower (customer_name, loan_number)!

So what is the difference between this:

select b.customer_name, l.amount 
from borrower b join loan l 
on b.loan_number = l.loan_number"

and this:

select b.customer_name, l.amount 
from borrower b join loan l 
using (loan_number)
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
AamKhayega
  • 89
  • 1
  • 1
  • 3
  • Don't you mean ON or WHERE? I don't see how you could use USING with a theta join. Can you show us an example? – Donal Oct 12 '14 at 09:45
  • Find customer names and their loan amounts. there are 2 relations: loan and borrower ● loan (loan_number, branch_name, amount) ● borrower (customer_name, loan_number) ■ select b.customer_name, l.amount from borrower b join loan l on b.loan_number = l.loan_number ■ select b.customer_name, l.amount from borrower b join loan l using (loan_number) – AamKhayega Oct 12 '14 at 09:56
  • I presume it is MYSQL? – Donal Oct 12 '14 at 10:01
  • read my question now. I have edited it with an example. – AamKhayega Oct 12 '14 at 10:01
  • You can use USING when the columns in the two join tables have the same name. See here: http://stackoverflow.com/a/11367066/379855 – Donal Oct 12 '14 at 10:04

0 Answers0