0

Having these tables:

clients
-------------------
id
name
town

companies
------------------
id
name

credits
------------------
clients_id
companies_id
credit

Example:

clients
-------------
1  john doe   London
2  jane smith Paris

companies
-------------
1  mycompany1
2  mycompany2

credits
-------------
1  1   5000
1  2   3250
2  2   4500

How can I list all the clients including an additional column for each credit she has in a company? I also need to alias each of these columns in this fashion: "credit_"

Something like:

id  name        town    credit_1  credit_2
1   john doe    London  5000      3250
2   jane smith  Paris   NULL      4500

I'm not sure if doing two LEFT JOINS to credits would work.

luis.ap.uyen
  • 1,314
  • 1
  • 11
  • 29

0 Answers0