Jason Williard wrote:

I know that it is possible to do this, though I don't know how.

I have 2 tables containing information about trouble tickets. One of the
tables (table2) contains information about every ticket ever received,
including tickets that were deleted from the system. For this reason,
table2 has ~450,000 records where table1, which holds the good tickets,
has only ~4500. I would like to clear the useless data out of table2,
but don't want to run 450,000 queries to compare them one row at a time. The two tables share a common id, though one is referred to as tickid
while the other is referred to as ticketidchar.


Is there an easy way, using just a few queries, to select all the rows in
table2 where ticketidchar does not exist in table1?

Thank You,
Jason

It sounds like you want a multi-table delete. Assuming tickid is part of the new table, something like:


  DELETE table2 FROM table2 LEFT JOIN table1 ON ticketidchar = tickid
  WHERE tickid IS NULL;

See the manual for details <http://dev.mysql.com/doc/mysql/en/DELETE.html>.

 Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to