Have two tables:
Task:
Make a table with fields:
- name of acquiring_company;
- name of acquired_company;
price_amount
;funding_total
;
Ignore those transactions in which the purchase amount (price_amount) and amount of investment (funding_total) is zero
SELECT
a.acquiring_company_id,
a.acquired_company_id,
a.price_amount,
c.funding_total
FROM acquisition a
LEFT JOIN company c
ON a.acquired_company_id = c.id
WHERE price_amount <> 0 AND funding_total <> 0
Maybe a dumb question, but how can I add names to acquiring_company and acquired_company (company.name
)? I don’t understand it because there are two id
fields. I can’t use JOIN on both of them.
2
Answers
Join the same table twice with different alias names
Yes, you can. And should.
Test the query in Db<>fiddle.