• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DELETE SQL Question

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have two tables, A and B, and I'd like to delete all records from A in which two of the columns match two columns in B - here's what my tables look like:



There are more columns in each table, but these are the ones I'd like to matc upon. When all is said and done, I'd like table A to look like this:



I'm a little unsure on how to write the SQL. I think I can do this:



I think that'll work, but I don't really like the syntax. It just doesn't seem obvious to me what that query will do and I'd like to have somewhat more readable SQL.

Any advice on a straightforward way to do this deletion?

Thanks,
Corey
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Delete FROM mytable A
WHERE EXISTS (SELECT 1
FROM myothertable B
WHERE A.PersonID = B.PersonID
AND A.ServiceID = B.ServiceID)
[ November 08, 2007: Message edited by: Paul Campbell ]
reply
    Bookmark Topic Watch Topic
  • New Topic