0

I have 2 tables and i am a little confused...

      |products|                          
________________________
|  id  | products_name |
|______________________|
|   1  |  iphone4      |
|   2  |  htc desire   |
    etc.............


     |special_price|
________________________
|  id  | products_price|
|______________________|
|   1  |  400          |
|   2  |  500          |
    etc.............

All i want to do is:

DELETE (ALL) FROM special_price WHERE products_name='iphone4'

How can this happen?

3
  • Why don't you just DELETE FROM special_price WHERE products_name='iphone4' ? Commented Jan 5, 2012 at 12:05
  • @Li0liQ: because products_name is in another table. Commented Jan 5, 2012 at 12:06
  • @Sergio Tulentsev Sorry, I've overlooked that. Commented Jan 5, 2012 at 12:07

2 Answers 2

4

You need to find the id(s) for that product_name, try this:

with IN: (useful for complex conditions)

DELETE FROM special_price 
WHERE id IN ( SELECT id FROM products WHERE products_name = 'iphone4' )
Sign up to request clarification or add additional context in comments.

Comments

4

Try this:

DELETE sp FROM special_price sp
INNER JOIN products p ON p.id = sp.id
WHERE p.products_name = "iphone4";

3 Comments

this will delete from sp table only
Yes, correct. That's what I meant. OP probably doesn't want to delete the product itself, just the special offer on it.
I think you meant to write: DELETE sp FROM ... so rows only from table special_price are deleted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.