Error Code 1241 Operand should contain 1 column(s)

44 Views Asked by At

delete from invoices where client_id = ( select* from clients where name = 'Myworks' );

I'm trying to delete a row of data for a client from another table called invoices, but it throws me an error 1241. What am I missing here?

1

There are 1 best solutions below

1
David On

When you do this:

where client_id = ( select* from clients where name = 'Myworks' )

If that clients table has more than one column, which column should client_id be compared to? MySQL doesn't know, and won't decide for you, and so it's giving you an error message.

Specify one column for that identifier:

where client_id = ( select client_id from clients where name = 'Myworks' )

(This is assuming the target column is also called client_id. Use whatever column you wish.)

As an aside, using = there is weird to me. I'm not sure if the system supports it, it may and this may be a non-issue. But if it doesn't, use IN instead. (Which just makes more sense to me semantically anyway.) For example:

where client_id IN ( select client_id from clients where name = 'Myworks' )