I have this select query:
SELECT * FROM `jos_users`
left join jos_clientes on jos_users.id = jos_clientes.id_user
where jos_clientes.id_user is null
and email like '%novousuario%'';
This query returns me all jos_users that have not a row on the jos_clientes table.
The jos_clientes schema is:
create table jos_clientes(
id int(11) not null auto_increment primary key,
id_user int(11) not null,
codigo_cpf_cnpj varchar(20) not null,
type varchar(4) not null
);
Is there any way to, for each row, I insert a new row in jos_clientes?
foreach jos_users
INSERT INTO jos_clientes VALUES (null, jos_users.id_user, jos_users.username, IF(length(jos_users.username)>11,'cnpj','cpf'));
How can I do this with sql on mysql?