1

I have 2 tables in Postgresql. Both these are in different schema. I want the output as in the shared screenshot.

Suppose,for field HDRConfig,if the output value is SE then I want the output as Software Engineering instead of SE. How do I show these with the rest of the columns i.e HDRConfig, AbrConfig & SbrConfig ?

enter image description here

1

1 Answer 1

1

Simple LEFT JOIN:

SELECT l0.Code_Desc AS HDRConfig,
       l1.Code_Desc AS AbrConfig,
       l2.Code_Desc AS SbrConfig
FROM Equipment e
LEFT JOIN Lookup l0
  ON e.HDRConfig = l0."Code"
LEFT JOIN Lookup l1
  ON e.AbrConfig = l1."Code"
LEFT JOIN Lookup l2
   ON e.SbrConfig = l2."Code";

SqlFiddleDemo

╔═══════════════════════╦═══════════════════════╦══════════════════════╗
║      hdrconfig        ║      abrconfig        ║      sbrconfig       ║
╠═══════════════════════╬═══════════════════════╬══════════════════════╣
║ Software Engineering  ║ Software Engineering  ║ Software Engineering ║
║ (null)                ║ Analog System         ║ Floppy Primary       ║
╚═══════════════════════╩═══════════════════════╩══════════════════════╝

Using correletad subqueries(inefficient way):

SELECT 
  (SELECT Code_desc FROM Lookup WHERE "Code" = e.HDRConfig) AS HDRConfig,
  (SELECT Code_desc FROM Lookup WHERE "Code" = e.ABRConfig) AS ABRConfig,
  (SELECT Code_desc FROM Lookup WHERE "Code" = e.SbrConfig) AS SbrConfig
FROM Equipment e;

SqlFiddleDemo2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.