I am trying to return results that replace record Ids with their more human readable description values. Changing the column names via AS is simple enough but I think a subquery is going to be needed to take an ID values such as PT1 and get the Description value as a replacement.
For instance I have a table1 with some columns like:
id| Paper | Coating | CreatedOn | Type
1 | pid3 | cid5 | some date | tid2
2 | pid2 | cid8 | some date | tid3
3 | pid1 | cid1 | some date | tid4
Then table2 has details on the reference id in the parent table:
id| fKey | description |
1 | pid3 | some user friendly description |
1 | pid1 | some other description |
1 | pid2 | something else |
Similar for tables three and four
I tried to use a JOIN linking the Paper IDs but this returned no values
SELECT table1.Paper as ‘Paper Name’, table1.Coating, table1.CreatedOn, table1.Type, table2.description
FROM table1
JOIN table2 ON table1.Paper = table2.fKey
My actual query is as shown but the table names were altered:
SELECT PD_ComboRun.RNId AS 'RUN #', PD_ComboRun.RNQty AS Quantity,
PD_ComboRun.PTId, PD_ComboRun.PSId AS Size, PD_ComboRun.RNType AS 'Run Type',
PD_ComboRun.PCId AS 'Press Coating', PD_ComboRun.UVFid AS 'UV Finish',
PD_ComboRun.Notes AS 'Special Instructions', PD_ComboRun.CreatedOn AS 'Date Created',
SM_PaperType.PTCode AS Paper, SM_PaperType.PTId AS Expr1
FROM PD_ComboRun
LEFT JOIN SM_PaperType ON SM_PaperType.PTId = PD_ComboRun.PTId
Can someone please point me the right direction to achieve this goal? Thanks!
This works perfectly as I presume you need. I modified it to use your tables and fields.
RESULTS
@table1
@table2
@combined
