简体   繁体   中英

MySQL - Taking data from one column in a table and inserting it into another table

I have two tables users(id, username, password) and user_badges(user_id, badge_id, badge_slot)

I would like to insert the data (id from user table, FBB, 0) for every row in the users table.

How can I do this?

Thanks!

You want this?

INSERT INTO user_badges(user_id, badge_id, badge_slot)
SELECT id, 'FBB', 0
  FROM users;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM