[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Query to remove lines from 1 table by referencing another table

Posted on 2011-02-13
2
Medium Priority
?
292 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 1000 total points
ID: 34883149
delete from table1 where product not in (select product from table2)
0
 

Author Closing Comment

by:TG-Steve
ID: 34883189
worked like a charm thank you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 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