INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

 

RE: Problems with a "Delete From" query.

_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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close