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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine two queries

Status
Not open for further replies.

Itshim

Programmer
Apr 6, 2004
277
US
I have these two queries that I would like to combine, but I am to the point, where I'm not sure its possible.

The two queries are:
Code:
//delete from correlation table
DELETE
FROM site_keyword
WHERE keyword_id = 50

//clean up keyword table
DELETE
FROM keyword k LEFT JOIN site_keyword sk
ON k.keyword_id = sk.keyword_id
WHERE sk.keyword_id IS NULL
The first query actually deletes from several tables, but I have paired it down for this post. I only want to delete records from the 'keyword' table if the keyword_id no longer exists in the site_keyword table.
 
I'm sorry the second query should read:
Code:
DELETE
FROM keyword k LEFT JOIN site_keyword sk
ON k.keyword_id = sk.keyword_id
WHERE sk.keyword_id IS NULL
 
I'm sorry the second query should read:
Code:
DELETE keyword
FROM keyword k LEFT JOIN site_keyword sk
ON k.keyword_id = sk.keyword_id
WHERE sk.keyword_id IS NULL
 
Thank you for the definitive answer. Wasn't exactly what I was hoping for, but at least now I know and can continue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top