[UPHPU] database architecture for type with 2 parents

Roberto Mello roberto.mello at gmail.com
Sun Sep 21 09:48:57 MDT 2008

On Sat, Sep 20, 2008 at 6:25 PM, Richard K Miller
<richardkmiller at gmail.com> wrote:
>> CREATE VIEW mysitesview AS
>> SELECT m.id, m.type, COALESCE(d.domain, sd.domain) AS site, m.hosting,
>> m.fk_id
>> FROM  mysites m
>>   LEFT OUTER JOIN domain d ON m.fk_id = d.id AND m.type = 'domain'
>>   LEFT OUTER JOIN subdomain sd ON m.fk_id = sd.id AND m.type = 'subdomain'
> This query worked great, as did Brandon's query with if() instead of
> coalesce(). And the resulting VIEW can be edited -- exactly what I wanted.
> Thanks!

Excellent. I'm glad it worked out. FYI, I used COALESCE in my solution
because I try to stick to standard SQL whenever possible, only
resorting to database-specific things if necessary.



More information about the UPHPU mailing list