Let's say I have a coding table containing various types, for example:
ID EncodingName ------------------ 1 UTF-8 2 ISO-8859-1
And another EncodingMapping that uses these identifiers to keep track of which encodings to convert From and To:
ID ItemId_FK EncodingFromId_FK EncodingToId_FK ------------------------------------------------- 1 45 2 1 2 78 1 2
I want to create an SQL statement that produces the following result when ItemId_FK = 45 (for example):
FromEncoding ToEncoding ------------------------- ISO-8859-1 UTF-8
It seems like this would be simple enough, but I can't get the JOIN to work by returning a single line in this format.
What I still have (THIS IS WRONG):
SELECT EncodingName As FromEncoding, EncodingName As ToEncoding FROM Encoding LEFT JOIN EncodingMapping As em ON Encoding.ID = em.EncodingFromId_FK OR Encoding.ID = em.EncodingToId_FK WHERE ItemId_FK = 45
source share