Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
BE CAREFUL of lines like that in FoxPro, since you didn't include a semicolon, it will interpret the first line before throwing an error when it reaches the second line.Try
DELETE FROM bell_lns
WHERE newtob = 1 AND custno IN
(
SELECT custno FROM test1
GROUP BY custno
HAVING COUNT(custno) > 1
);
The HAVING parameter is intended for aggregate functions, so you can't use it like that.Hi all,
I'm having an issue with a "DELETE FROM... HAVING"... How can I make this command work please?
delete * FROM bell_lns where newtob = .T. and HAVING COUNT('custno')>1 and custno in (sele custno from test1)
Thanks,
FOXUP
![]() |
---|
The HAVING clause without a GROUP BY clause acts like the WHERE clause. If the HAVING clause contains no aggregate functions, use the WHERE clause for faster performance. |
Completely agree. I would go even further and I would create an updatable view, browse it first and if I like what I see, DELETE ALL==> TABLEUPDATE()===>Requery(), unless FoxUp is not familiar with viewsThe HAVING parameter is intended for aggregate functions, so you can't use it like that.
Since you seem to be new to SQL Queries, you should avoid using the delete function until you can first successfully do a SELECT with the intended results.
For example:
SELECT CustNo, count(*) as MyCount from MyTable where Custno in (select CustNo from Test1) group by CustNo having MyCount > 1
If you see what you intended to see in that result, you can swap the word SELECT with DELETE with the same results.
Again, be CAREFUL with DELETE using SQL because you need to know what it would've selected before you trust your code to do a delete.
As a developer if I could make one change to SQL is that they remove the ability to use the DELETE command without any conditions.Completely agree. I would go even further and I would create an updatable view, browse it first and if I like what I see, DELETE ALL==> TABLEUPDATE()===>Requery(), unless FoxUp is not familiar with views