Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with a "Delete From" query.

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
0
0
US
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

 
_maybe_ something like:

Code:
DELETE FROM tkhist1 WHERE tkthist1.ticketNo NOT IN (select arhist.transno FROM arHist)

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:
SELECT tkthist1.ticketNo WHERE tkthist1.ticketNo NOT IN (select arhist.transno FROM arHist)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top