Hello i am trying to solve this issue tru MYSQl without additional server side code.
1.event
+--------------------------+-------------------+
|id | online_payee_id |
+--------------------------+-------------------+
| 1 | 110 |
| 2 | 330 |
|44 (not in charity table) | 330 |
+---+------------------------------------------+
2.charity
+---+------------+------------+
|id | event_id | payee_id |
+---+------------+------------+
| 1 | 1 | 330 |
| 2 | 2 | 330 |
+---+------------+------------+
what i want is union this two tables into a new table with a flag indicating "isEvent" and "Charity payee" OR "Event payee & Charity payee" for example:
Note online_payee & payee_id are basically same field.
+---+------------+----------------------------+
|id | event_id | flag |
+---+------------+----------------------------+
| 1 | 1 | Charity payee |
| 1 | 2 | Event payee & Charity payee|
| 2 | 44 | IsEvent |
+---+------------+----------------------------+
I have tried something like this but getting dupe results.
SELECT
COALESCE(EV.id, EV2.id) AS `id`,
IF(EV.online_payee_id AND EC.payee_id,"Event payee / Charity payee",
IF(EV.online_payee_id,"Event payee","Charity payee"))
AS `type`
FROM `payee` AS `P`
LEFT JOIN `event` AS `EV` ON P.id = EV.online_payee_id
LEFT JOIN `charity` AS `EC` ON P.id = EC.payee_id
LEFT JOIN `event` AS `EV2` ON EC.event_id = EV2.id
WHERE (P.id = 330)
AND (EC.payee_id IS NOT NULL OR EV.online_payee_id IS NOT NULL)