MySQL Forums
Forum List  »  General

Re: join tables with substitution where values exist, else use existing values
Posted by: David Koski
Date: February 16, 2015 02:03PM

I found a solution. Use two joined querries, one for NULL values and one for NOT NULL values:

(SELECT transport.key, transport.transport
FROM transport left join transport_aliases ON transport.transport=transport_aliases.alias
WHERE transport_aliases.alias IS NULL)
UNION
(SELECT transport.key, transport_aliases.transport
FROM transport left join transport_aliases ON transport.transport=transport_aliases.alias
WHERE transport_aliases.alias IS NOT NULL)

This combines values from the main table that don't exist in the alias table.

David

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.