0

Evening all, I have the following SQL Query for PDO:

DELETE FROM group_members WHERE group_id IN( SELECT * FROM groups WHERE group_owner = 1 ) AND user_id = 2

And for some strange reason I keep getting the following message:

#1241 - Operand should contain 1 column(s)

Now; I understand what the message means but I can clearly see that I've set a condition after the and so im not too sure what's going on.

Thanks for any help! :o) I'm sure its a noob mistake ;)

2
  • That was it! I knew it was something simple. Thanks for that. You should post that as a solution ;) Commented Apr 12, 2012 at 8:41
  • I'm on my iPad. It's too much effort to format code, etc. Commented Apr 12, 2012 at 8:42

4 Answers 4

1

You use * in your subquery, you need to select the correct column:

SELECT group_id FROM groups WHERE group_owner = 1 
Sign up to request clarification or add additional context in comments.

Comments

1

I know you already have an answer, but also, consider using a join instead of the subquery:

DELETE gm.*
FROM group_members AS gm
JOIN groups g
  ON gm.group_id = g.id
WHERE gm.user_id = 2
  AND g.group_owner = 1

Comments

1

Try this:

DELETE FROM group_members
WHERE group_id
    IN ( SELECT group_id FROM groups WHERE group_owner = 1 )
  AND
    user_id = 2

Comments

0

Give it a try-

DELETE FROM group_members WHERE user_id = 2 and group_id IN( SELECT * FROM groups WHERE group_owner = 1 )

I have not tested this and does not even know your desired result, but give this a try.

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.