DELETE FROM Loan_GL_LoanDetails Where loan_id IN(SELECT TOP 1 * FROM Loan_GL_LoanDetails LD
Inner Join Loan_GL_LoanMaster LM on LM.loan_id=LD.loan_id
where LM.loan_no = @loan_no ORDER BY LD.ld_id DESC)
Error :
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 10, 2014, 11:32 PM EST
ex:
Ajith kp132 reputationPosted Feb 10, 2014, 11:40 PM EST
DELETE FROM Loan_GL_LoanDetails WHERE loan_id IN( SELECT TOP 1 loan_id FROM Loan_GL_LoanDetails WHERE loan_id ='35' Order by ld_id DESC)
.
I tried this code also but all the rows are deleted, want to delete the last row only
ld_id is table-2 primary key
loan_id is table 1 primary key & table 2 forign key
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 11, 2014, 1:53 AM EST
I hope you want to delete the record from details table only, if not tell me
or else you can use LAST() function to get last row