0

I wanted to know if is there any solutions to delete multiple rows in one query?

I'm using a select element with multiple input so I have an array in my $_POST when I'm sending my form.

For example, I want to unsubscribe an users from one table to more than one lesson So I have:

users.id | lesson.id
--------------------
1        | 1
1        | 2
1        | 3
1        | 4

My select post me an array with the lesson.id:

Array
(
    [0] => 2
    [1] => 3
    [2] => 4
)

How can I with only one query, delete all rows from my table ?

BTW, I know the users.id all the time.

1
  • Please show your select. Commented Dec 10, 2012 at 23:45

1 Answer 1

2

If you want to delete just these three lesson_ids

delete from lesson_table
where users_id = 1 and lesson_id in (2, 3, 4)

If you want to delete all but one arbitrary lesson and you know, user 1 has 4 lessons, then you can limit the delete to 3 lesson_ids

delete from lesson_table
where users_id = 1
limit 3
Sign up to request clarification or add additional context in comments.

Comments

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.