0

I have two tables: campaigns and accounts

In accounts I have accountid column and accountName column.

In campaigns I have ExternalCustomerId and AccountDescriptiveName. ExternalCustomerId holds accountid

So what I am trying to do is to get list of all campaigns and join the account Name to table where External Customer Id = account id

enter image description here

But all what I have tried without any luck

Thanks

gturri
  • 13,807
  • 9
  • 40
  • 57
user2413244
  • 231
  • 4
  • 16
  • 1
    Please show what you tried. This looks like it should be a simple `LEFT JOIN`. – Barmar Dec 26 '14 at 19:25
  • 1
    I agree with Barmar. This may help: http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ However, is the problem with the SQL or the php? – xQbert Dec 26 '14 at 19:44
  • possible duplicate of [Difference between INNER and OUTER joins](http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins) – xQbert Dec 26 '14 at 19:46

2 Answers2

1

Try it:-

SELECT ExternalCustomerId,AccountDescriptiveName,accountName FROM accounts LEFT OUTER JOIN campaigns ON accounts.accountid=campaigns.ExternalCustomerId;

For more knowledge follow MySQL documents http://dev.mysql.com/doc/refman/5.0/en/select-optimization.html

Bit_hunter
  • 789
  • 2
  • 8
  • 25
0

Yes you need a JOIN, here is an example:

SELECT c.ExternalCustomerId , c.AccountDescriptiveName, a.accountName 
FROM campaigns c
LEFT JOIN accounts a
ON c.ExternalCustomerId = a.accountid
WHERE c.ExternalCustomerId = ?

Check the docs to learn more about the syntax

meda
  • 45,103
  • 14
  • 92
  • 122