Author |
Topic |
mfdarvesh
Starting Member
10 Posts |
Posted - 2005-12-12 : 06:38:01
|
I have three tables Emp, Edu and Exp the relationship between them is like this:Emp -> Edu (Empid)Emp -> Exp (Empid)both tables are linked with EmpId in a Sinlge master table. I want to retrive all the information from three tables and dispaly them on a single page. Is is possible, below is the query which i am using and it gives wrong resut. Select e.empid, d.qualifcation, p.naturefrom emp e, edu d, exp pwhere e.empid = d.empidand e.empid = p.empidHow can I correct that, the same result is obtained if i use inner join our left outer join, please help me |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-12 : 06:43:18
|
Try thisSelect e.empid, d.qualifcation, p.naturefrom emp e inner join edu d on e.empid = d.empidinner join exp p on e.empid = p.empidOtherwise post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-12 : 06:46:52
|
Logically query is correct.One doubt.R u sure the relation between Emp->Edu and Emp->Exp is one to one? ... or is it one to many?Surendra |
|
|
mfdarvesh
Starting Member
10 Posts |
Posted - 2005-12-12 : 06:56:50
|
surendrakalekar, One to many from Emp -> edu and One to many from emp -> Expmadhivanan, the query return error in join |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-12 : 07:46:56
|
quote: Originally posted by mfdarvesh surendrakalekar, One to many from Emp -> edu and One to many from emp -> Expmadhivanan, the query return error in join
One to many...It will be better if you post the structure of your tables with some sample data and let us know the desired output.Surendra |
|
|
mfdarvesh
Starting Member
10 Posts |
Posted - 2005-12-12 : 07:58:27
|
Table Empempid (pk)nameaddress etc.table eduempid (fk)degreeyeargradetable expempid (fk)periodduties etc.these are three tables, edu and exp table may have diffrent number of rows for a single employee, My boss wants that all the information may be displayed on single sheet, this is actually problem |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-13 : 01:38:58
|
As per your postings you required the result in the below given format. Correct me if I am wrong.empid qualification nature1 BE Officer1 MBA Admin1 NULL MD2 MCS Manager2 PHD NULL3 B.COM Worker3 M.COM Officer3 MCA Asst. Manager4 BCS Developer4 NULL TL4 NULL PLTo achieve such kind of result either you need to change your table structure. OR You can achieve this by using the #temp table and cursors. By using cursors you can store the data into #temp table and then get back those result to display. Your #Temp table must have all the required fields from all the tables and put NULL where the record/values are not exists.Surendra |
|
|
mfdarvesh
Starting Member
10 Posts |
Posted - 2005-12-13 : 02:02:11
|
yes Surendra you are right, my boss want to print actually all this information on a single page because each employee has few lines in education as well as in experience. So all that information can be printed on single page but I was unable create a view for that. If I can use #table, please guide me how can do that..If you are so kind to me, please tell me how I can change the structure of tables. I actually want to keep some more information too, like medical record, family etc. |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-13 : 02:11:17
|
1. Create #temp table which is having columns like empid, qualification, nature2. Create cursor for both EDU and EXP tables3. Fetch field values into variables.4. Loop both of them (one inside another)5. Insert values into #temp table6. goto next records.....7. close/deallocate the cursor8. display the result.9. remove the #temp table.Surendra |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-13 : 02:15:24
|
Can you post some sample data and the result you want?MadhivananFailing to plan is Planning to fail |
|
|
mfdarvesh
Starting Member
10 Posts |
Posted - 2005-12-13 : 02:46:34
|
dear Madhivanan can you given email address, I can send you direct file because here it is not possible to attch file |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-13 : 02:56:52
|
No need to attach files. Paste the data hereMadhivananFailing to plan is Planning to fail |
|
|
|