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

SQL Multiple join from 2 table to 1

I want to join from 2 table to 1. I have tried it multiple times but I can’t figure out the correct code. The name ‘Edvard Supica’ which is the full_name from suser table I want to be on the place of User ID and in 1 record.

how it looks like now'

SELECT w.*, m.vin AS 'workbook_vin'
FROM workbook w
LEFT JOIN machines m ON m.id = w.machine_id
            
UNION

SELECT w.*, s.full_name AS 'user_full_name'
FROM workbook w
LEFT JOIN suser s ON s.id = w.user_id

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

>Solution :

If you’re joining both machines and susers on workbook, you can do both JOINs in the same query without needing to use UNION.

SELECT
    w.*,
    m.vin AS 'workbook_vin',
    s.full_name AS 'user_full_name'
FROM
    workbook w
    LEFT JOIN machines m ON m.id = w.machine_id
    LEFT JOIN suser s ON s.id = w.user_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