people_table

 id project_id comp_id  people_name
    1   13         1        john
    2   16         2        rob
    3   18         1        jack
    4   18         2        lee


company_table

 id project_id comp_name
    1   21         axn
    2   13         ibm
    3   15         anz

最佳答案

你需要这个:

SELECT A.*,B.*
FROM people_table as A
INNER JOIN company_table as B
ON A.project_id = B.project_id


您应该检查sqlfiddle:

http://sqlfiddle.com/#!2/4ecd2/1

关于mysql - 如何在MYSQL中基于project-id从两个表中获取所有记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22953016/

10-11 16:25