我想为tbl_pop_up_messages中的tbl_users为每个用户添加一个seprate弹出窗口。例如,如果我在tbl_users中有50个用户,那么应该在tbl_pop_up_messages中为每个用户添加50行。每个登录的用户都会看到弹出窗口,弹出窗口将在clic.My conern只是要添加后停用行。请指导。
SELECT user_id FROMt bl_users;
INSERT INTO tbl_pop_up_messages (user_id, popup_text, active)
VALUES ('3', 'Pop Up Text', '1');
答案 0 :(得分:2)
您可以使用INSERT INTO SELECT
执行此操作,如下所示,前提是您有一个表格,其中包含您希望添加到每个用户的弹出消息:
INSERT INTO tbl_pop_up_messages (user_id, popup_text, active)
SELECT usr.user_id
, pmt.popup_text
, 1
FROM tbl_users usr
cross join popup_messages_table pmt
或者,你可以使用更多的“直接”和漫长的方法,以防你没有弹出消息表,如下所示:
INSERT INTO tbl_pop_up_messages (user_id, popup_text, active)
SELECT usr.user_id
, pmt.popup_text
, 1
FROM tbl_users usr
cross join (select 'Pop Up Text' popup_text
union all
select '2nd Pop Up Text'
union all
select '3rd Pop Up Text'
-- and so on until you reach X messages or how many you want for each user
) pmt
如果您只需为每个用户插入一条弹出文字信息,则:
INSERT INTO tbl_pop_up_messages (user_id, popup_text, active)
SELECT usr.user_id, 'Pop Up Text', '1'
FROM tbl_users
答案 1 :(得分:1)
您可以这样做:
INSERT INTO tbl_pop_up_messages(user_id, popup_text, active)
SELECT u.user_id, 'Pop Up Text', '1'
FROM tbl_users u;