SELECT * FROM (
SELECT appointmentDatetime, accountOwner, bankerId FROM `appointments` WHERE accountOwner = '5'
) AS `appointment`
LEFT JOIN `users` AS `accountOwner` ON (accountOwner = userId)
LEFT JOIN `users` AS `banker` ON (bankerId = userId)
UNION
SELECT * FROM (
SELECT appointmentDate, accountOwner, bankerId FROM `appointments` WHERE bankerId = '5'
) AS `appointment`
LEFT JOIN `users` AS `accountOwner` ON (accountOwner = userId)
LEFT JOIN `users` AS `banker` ON (bankerId = userId)
Here's what I want back:
[
{
banker: {
firstName: "John",
lastName: "Smith",
userId: "7"
},
accountOwner: {
firstName: "Marty",
lastName: "Sullivan",
userId: "5"
},
appointment: {
appointmentDatetime: "2014-09-01 12:00:00",
accountOwner: '5',
bankerId = '7'
}
},
{
accountOwner: {
firstName: "Fred",
lastName: "Dunlop",
userId: "11"
},
banker: {
firstName: "Marty",
lastName: "Sullivan",
userId: "5"
},
appointment: {
appointmentDatetime: "2014-08-13 15:00:00",
accountOwner: '11',
bankerId = '5'
}
}
]