Problems with a "Delete From" query.
Problems with a "Delete From" query.
(OP)
Hi. I'm using psql. We are going to be upgrading to the new SQL version of our ticketing program JWS ver 4 and I am trying to purge some of the records from our ticket file. I purged the invoice table for all invoices < 7/1/2009 and now I'm trying to set up a query to delete all the tickets that are on the purged invoices. Here is my query for the count of the number of Tickets that won't be purged:
select count(t1.ticketno) from tkhist1 t1, arhist t2 where t1.invoiceno = t2.transno;
Now I need to write a "delete from tkhist1" query to delete only the tickets where t1.invoiceno <> t2.transno. I can't seem to find the syntax to do it. I know how to do a delete from a single table, but this has me stumped.
Thanks for any help you can give me.
Cathy
select count(t1.ticketno) from tkhist1 t1, arhist t2 where t1.invoiceno = t2.transno;
Now I need to write a "delete from tkhist1" query to delete only the tickets where t1.invoiceno <> t2.transno. I can't seem to find the syntax to do it. I know how to do a delete from a single table, but this has me stumped.
Thanks for any help you can give me.
Cathy
RE: Problems with a "Delete From" query.
CODE
I'm not sure how well Pervasive does (or does not) support correlated sub-queries and/or if they are supported in a DELETE FROM statement's WHERE clause.
the above, provided it was syntastically correct, lists all the transno's from arhist, and then says "Ok, now delete from tkhist1 when there is no match".
MAKE SURE YOU TEST THIS FIRST. A select statement is a good way to see what will be deleted:
CODE