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

Iftikar HussainPosted Jul 16, 2013, 6:35 AM
Regards,
Iftikar
Kavi sujaPosted Jul 16, 2013, 7:00 AM
Thank you very much.It's working....
Kavi sujaPosted Jul 16, 2013, 6:26 AM
I try this.But the data not retrived from commonpersoninfo,departmentview.(I want other data with 'mobileno' field as null)
Iftikar HussainPosted Jul 16, 2013, 6:15 AM
Regards,
Iftikar
Kavi sujaPosted Jul 16, 2013, 6:11 AM
I alrady check in this way for did = 365.But the data not retrieved.Actually commonpersoninfo ,departmentview have data for did=365.The tables whosinfo,contactinfo are not contains the data for did=365.So when i run following query no data returned.But i want to return all the data with mobileno as Null value.
WHERE
A.pkey=DID;
Iftikar HussainPosted Jul 16, 2013, 6:03 AM
Regards,
Iftikar
Kavi sujaPosted Jul 16, 2013, 5:59 AM
Thank you for your reply.Now it's working for me.But i've another issue here.Sometimes the table 'contactinfo' doesn't have data(ie. mobileno) for particular whosinfo_pkey or 'whosinfo' doesn't have data for particular hisPkey.That time,I want to get another data except mobileno.Using your last query I can include the data with mobile number.But whenever execute query for the data not available in 'contactinfo','whosinfo' I want to generate other fields with mobilenumber as null.
Iftikar HussainPosted Jul 16, 2013, 5:29 AM
Try like this
Regards,
Iftikar
Kavi sujaPosted Jul 16, 2013, 5:22 AM
Table - commonpersoninfo--- Fields : pkey,salutationlist_pkey,firstname,middleinitial,lastname,dateofbirth,education,speciality,gender.
Table - departmentview--- Fields : commonpersoninfo_pkey,deptid.
Table - contactinfo--- Fields : mobileno,whosinfo_pkey.
Table - whosinfo--- Fields : wkey,hisPkey
I want to get salutationlist_pkey,firstname,middleinitial,lastname,dateofbirth,education,speciality,gender,mobileno,
deptid based on particular key.This key is pkey in 'commonpersoninfo',commonpersoninfo_pkey in 'departmentview',hisPkey in 'whosinfo'.In above procedure all data are retrieved expect mobileno from contactinfo table.
sample Data:
commonpersoninfo-345,'Mr','Nirmal','Paul','J','1986-01-06','MBBS','OHS','Male'.
departmentview-345,'3'.
contactinfo- '9600765342',342
whosinfo- 342,345
Pankaj PandeyPosted Jul 16, 2013, 5:17 AM
Iftikar HussainPosted Jul 16, 2013, 4:57 AM
Could provide example for your 3 table data? How exactly you want the output?
Regards,
Iftikar