Mysql Insert with subquery -


i'm trying insert several records :

set @user_id = (select `id` users `email` in( 'carlos+01@comp.com', 'carlos+223344@comp.com' ) );  set @badge_id = (select `id` badges `slug` = 'elearning_nutrition');  insert `instructor_badges` (`id`, `user_id`, `badge_id`, `is_active`, `is_manual`, `created`) values (uuid(), @user_id, @badge_id, '1', '0', now()); 

but im getting error:

[error in query 1] subquery returns more 1 row

in case have insert 2 records. how perform query?

you try this. cartesian join users badges, though. if select 2 users , 2 badges 4 rows insert. think that's saying want achieve.

insert instructor_badges (id, user_id, badge_id, is_active, is_manual, created) select uuid(), users.id, badges.id, '1', '0', now() users  join badge users.email in( 'carlos+01@comp.com', 'carlos+223344@comp.com' ) && badges.slug = 'elearning_nutrition' 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -