Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find corresponding id values for records from different table

I have 2 tables with entries as:

Transition table:

From_Status_Id     To_Status_Id      PU_Id
    5                   1             868
    5                   2             868
    5                   3             868
    5                   4             868
    8                   5             868
    8                   2             868
    8                   3             868

Status table:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ProdStatus_Id      ProdStatus_Desc
        1                NoId-Staged
        2                NoId-Running
        3                Staged
        4                Running
        5                Complete
        8                Inprogress

I need the result in below format which would be basically the corresponding status desc value for a given status id.

Output:

from_status  to_status
Complete    NoId-Staged
Complete    NoId-Running
Complete    Staged
Complete    Running
Inprogress  Complete
Inprogress  NoId-Running
Inprogress  Staged

How can we achieve this result set using joins?

>Solution :

 SELECT S.ProdStatus_Des AS FROM_STATUS,S2.ProdStatus_Des AS TO_STATUS
 FROM Transition AS T
 JOIN Status  AS S ON T.From_Status_Id=S.ProdStatus_Id 
 JOIN Status  AS S2 ON T.To_Status_Id=S2.ProdStatus_Id  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading