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.
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Biswa Pujarini MohapatraPosted Feb 11, 2014, 6:53 AM
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
Ajith kpPosted Feb 11, 2014, 4:40 AM
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 MohapatraPosted Feb 11, 2014, 4:32 AM
ex: