mysql join Two tables to get records

Posted by Saranya on Stack Overflow See other posts from Stack Overflow or by Saranya
Published on 2010-01-12T11:55:29Z Indexed on 2010/04/15 21:03 UTC
Read the original article Hit count: 312

Filed under:
|
|

Hai guys,

I have two tables Incharge and property. My property table has three fields 1stIncharge,2ndIncharge and 3rdIncharge. InchargeId is set as foreign key for all the above fields in the property table..

How to write a select statement that joins both the table.. I ve tried a bit but no result

select P.Id,P.Name,P.1stIncharge,P.2ndIncharge,P.3rdIncharge,I.Id from 
Property as P join Incharge as I where (\\How to give condition here \\)

Guys 3 fields P.1stIncharge, P.2ndIncharge, P.3rdIncharge has foreign key I.Id

Edit:

select P.Id,P.Name,P.1stIncharge,P.2ndIncharge,P.3rdIncharge,I1.Id from 
Property as P 
inner join Incharge as I1 on I1.Id=P.1stIncharge 
inner join Incharge as I2 on I2.Id=P.2ndIncharge  
inner join Incharge as I3 on I3.Id=P.3rdIncharge

and this query working

© Stack Overflow or respective owner

Related posts about mysql

Related posts about join