user1696335
user1696335

Reputation: 1

How to fetch all records from both the table based on project-id in MYSQL

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

Upvotes: 0

Views: 73

Answers (3)

kkk
kkk

Reputation: 1601

Try below.

select * from people_table p,company_table c where p.projectID=c.projectID

This displays project_ID column twice. So you can use distinct keyword to get one project id column.

Upvotes: 0

jmail
jmail

Reputation: 6132

you need this:

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

you should check the sqlfiddle:

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

Upvotes: 1

Sadikhasan
Sadikhasan

Reputation: 18598

Try with INNER JOIN

SELECT P.*,C.* 
FROM people_table P 
INNER JOIN company_table C ON P.project_id = C.project_id
WHERE P.project_id = $your_project_id;

Upvotes: 0

Related Questions