Hi,
Less of a drupal question, than a SQL question, but I am trying to create a view (that I am using with drupal) that will display the contents of 3 tables joined together.
However, I have one column that could be populated from 2 different places. Is that possible???
Here is the detail:
Acct ---has many---> Donations
Acct ---has many--->campaigns---has many--->Donations
Id like to create a view of Donations... that has a single field "Acct" that represents either the relationship with the Acct on the Donation, or the Acct that is referenced through the campaign table. The donation table does not have an Acct on it, if its related to a campaign.
so I want to be able to do something like this (pseudo sql)
Select (d.acct as "acct" || c.acct as "acct") from donations d left join campaigns c
Is this possible with just a SQL select clause??
thanks for your help!
Comments
Far from an SQL guru,
Far from an SQL guru, but....
If you know that results will always be in one column and not the other, the lazy way would be to just CONCAT() the two columns
If not, I beleive you will need to use a UNION statement
If you can't find a solution, MySQL have a IRC support channel with some very smart people you can ask for help
Thanks @aeternum... Both
Thanks @aeternum...
Both solutions worked. Although because the value was NULL it didnt like concatenating them, but a simple IF solved it.
Not sure which is more performant, but Im guessing the CONCAT rather than an whole UNION statement.
thanks again for quick reply!