I am trying to do something like
SELECT * from accounttable, peopletable, companytable
WHERE if accounttable.account_type = company
JOIN companytable
WHERE companytable.id = accounttable.company_id
ELSE IF accounttable.account_type = = person
JOIN peopletable
WHERE peopletable.id = accounttable.person_id
I’m sorry its a bit sqlenglish, but I really don’t know how to write it out.
What about something like:
I’ll join against both tables, so you’ll have fields of all three tables in the output. The fields from
peopletablewill beNULLifaccounttype != 'person', and those ofcompanytablewill beNULLwhereaccounttype != 'company'.You can find more on the
LEFT JOINsyntax in places like here…