3

I am working on a data export and need to return the values from a lookup table were there are multiple values to lookup from the same table in a single row.

Example

Example Tables

I essentially need to replace the 3 id columns with values from the lookup table keeping to a single row in the export.

Help is appreciated.

Gordon S
  • 33
  • 4
  • 2
    Did you try anything – Pரதீப் Oct 20 '16 at 16:27
  • Make an attempt before asking for help. As a nudge in the right direction, familiarize yourself with [SQL JOIN](http://stackoverflow.com/questions/17946221/sql-join-and-different-types-of-joins). – Tyler Roper Oct 20 '16 at 16:31
  • http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 –  Oct 20 '16 at 16:47
  • I apologize I got in a hurry and did not post everything properly.. I will ensure i do so in future. – Gordon S Oct 21 '16 at 15:35

1 Answers1

2
SELECT p.ID,
       p.NAME,
       q1.QualName,
       q2.QualName,
       q3.QualName
FROM   people p
       LEFT JOIN qualities q1
              ON q1.QualID = p.QualityID1
       LEFT JOIN qualities q2
              ON q2.QualID = p.QualityID2
       LEFT JOIN qualities q3
              ON q3.QualID = p.QualityID3; 
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
  • @Prdp, **(1)** Putting the commas on the left side is something I've learned from another developer. At first it seemed very awkward, but when I got used to it, it significantly enhanced my ability to to avoid syntax errors. **(2)** writing JOIN predicates' expressions one under the other helped me to avoid typos related to the tables' aliases. Since I've wrote queries involving 10th of tables, this was crucial. – David דודו Markovitz Oct 20 '16 at 17:23
  • But to me it looks ugly.. you can rollback the edit if you didnt like it ;) – Pரதீப் Oct 20 '16 at 17:24
  • Thanks.. I was just having a brain cramp about using the separate aliases for each join. I appreciate your help. – Gordon S Oct 21 '16 at 15:37