简体   繁体   中英

MYSQL Inner Join but with multiple columns

SELECT * FROM people p INNER JOIN job j ON p.job_id = j.id ORDER BY j.id ASC

The above is how I am using Inner Join to add j.id to p.job_id but what if I want to add j.description to j.job_description ?

I have tried

SELECT * FROM people p INNER JOIN job j ON p.job_id = j.id INNER JOIN job j ON p.job_desc = j.description ORDER BY j.id ASC

but this does not work.

The idea is to add contents from my table job to the table people

If I understand you right, this must be the solution:

SELECT * 
FROM people p INNER JOIN job j ON p.job_id = j.id and p.job_desc = j.description 
ORDER BY j.id ASC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM