Reputation: 165
I'm new posting here, and I was wondering if you could help me with a piece of mysql code:
INSERT INTO cliente (id_cliente,nombre,apellidop,apellidom,usuario,password,activo)
VALUES ((SELECT id_usuario,nombre,apellidop,apellidom,usuario,password,activo FROM usuario where id_usuario = 1));
It returns error 1241 (21000) operand should contain 1 column(s)
It's the same number of columns in the insert than the select, I got no idea what is going on? may be a newbie error?
Upvotes: 1
Views: 158
Reputation: 1033
You don't want to use 'VALUES' when SELECTing into an INSERT.
Instead try;
INSERT INTO cliente(id_cliente, nombre, apellidop, apellidom, usuario, password, activo)
SELECT id_usuario, nombre, apellidop, apellidom, usuario, password, activo
FROM usuario
WHERE id_usuario = 1;
Please refer to this link for more information.
Upvotes: 1