Solved

Query to remove lines from 1 table by referencing another table

Posted on 2011-02-13
2
281 Views
Last Modified: 2012-06-21
hi guys

I  have 2 tables referenced within a Mysql Database
 
Table 1 has arround 3000 lines of data and Table 2 has 1300 lines of data. both tables have different fields but both have a field named "product" which is a numeric number.

I am after some how querying the table with 1300 lines which has a field named product. And instructing Table 1 to delete any lines that DO NOT reference those that are within Table 2. Hereby me having 2 tables with 1300 lines.

The reason behind this is that Table 1 is a product table that has an entire product database but 1700 of them are old and not used. Table 2 has the stock control for the products and i only want to show the stock that has products on a website instead of people seeing products which are out of stock

Thank you in advance
0
Comment
Question by:TG-Steve
2 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 250 total points
Comment Utility
delete from table1 where product not in (select product from table2)
0
 

Author Closing Comment

by:TG-Steve
Comment Utility
worked like a charm thank you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now