Kavi suja

Kavi suja

  • NA
  • 298
  • 167.6k

MySql - Data From 3 tables -Left Joins

Jul 16 2013 3:55 AM
Hi,
   I have to retrieve data from 3 tables usind common id.I include the SP following.Here i have whosinfo table.This tables contains 2 fields,pkey and hisPkey.It stores the common id as hispkey.In this procedure i've to check continfo.whosinfo_pkey=whos.pkey for mobile number taken from contactinfo table.I want to use subquery here.But there are some errors.I dont know how to apply sub query.Can anyone helps me to solve this?


CREATE DEFINER=`root`@`%` PROCEDURE `SP_EditDoct`(in DID int)
BEGIN
SELECT 
Dept.Deptid,
DoctInfo.SalutationList_pkey,
DoctInfo.firstname,
DoctInfo.middleinitial,
DoctInfo.lastname,
DATE_FORMAT(DoctInfo.dateofbirth,'%m/%d/%Y'),
DoctInfo.education,DoctInfo.Speciality,
DoctInfo.gender,ContInfo.value as MobileNo
FROM
commonpersoninfo DoctInfo
LEFT JOIN
contactinfo ContInfo ON DoctInfo.pkey=ContInfo.whosInfo_pkey
INNER JOIN
departmentview Dept ON DoctInfo.pkey=Dept.CommonPersonInfo_Pkey
/* INNER JOIN whosinfo Whos ON ContInfo.whosInfo_pkey = Whos.hisPkey*/
WHERE  
DoctInfo.pkey=DID;
 

END

Answers (11)