1

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?

Drew
  • 24,851
  • 10
  • 43
  • 78

1 Answers1

1

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.

Community
  • 1
  • 1
Ross
  • 1,013
  • 14
  • 32