Hi I want to Insert Values into 2nd table where Fk in 2nd tabel is equal to PK in 1st table. Here if I Insert Values into 2nd table, Pk Values should not be Duplicated in 1st table.
What should be the INSERT JOIN Query...
| Loan_code | Loan_Type | Loan_Sanc | Intr_Type |
| 1 | Home | 30000 | Variable |
| 2 | car | 40000 | Fixed |
| 3 | Bike | 50000 | Variable |
| 4 | Personal | 60000 | Fixed |
| Chk_Num | Chk_Amount | Loan_code |
Plz Help
Iftikar HussainPosted Aug 4, 2013, 9:38 AM
Select E.Loan_code,E.Loan_type,E.Loan_Sanc,E.Intr_Type,
F.Chk_Num,F.Chk_Amount from BankDetails E join BankCheckDet F on E.Loan_code=F.Loan_code
Regards,
Iftikar
Aman JenPosted Aug 4, 2013, 9:34 AM
But then what it does , it fetches Loan_code colmn twice for join query
Iftikar HussainPosted Aug 4, 2013, 6:38 AM
Regards,
Iftikar
Aman JenPosted Aug 4, 2013, 5:40 AM
plz hav luk to this query it inserts records into second table based on PK of first table but if I try to retrive these tables by select join it is not showing any records
Insert Query:
Insert Into BankCheckDet (chk_Num,chk_Amt,Bank_Name)values(166,890000,'Indus bank') Select E.* From BankDetails E Left Join BankCheckDet F On E.Loan_code=F.Loan_code where E.Loan_code =4
Select Join Query:
Select E.* ,F.* from BankDetails E join BankCheckDet F on E.Loan_code=F.Loan_code
Plz help...
Iftikar HussainPosted Aug 4, 2013, 3:39 AM
If you want only single record for each Loan_Code in your second table, then declare Loan_Code itself as primary key in your second table. Then you no need any join. We declare FK keeping in mind that it is a child table where parent id can be repeated. Let me know if you need something else.
Regards,
Iftikar