[英]Mysql select user_ID and use these to construct INSERT statement, possible?
Is it possible to unite these two mysql commands? 是否可以将这两个mysql命令结合在一起?
I need user_id
from the first sql command, to be used inside the INSERT
statement. 我需要第一个sql命令中的
user_id
,以便在INSERT
语句中使用。
SELECT DISTINCT(user_id) FROM wp_usermeta WHERE meta_key = "wp_capabilities";
INSERT INTO wp_usermeta (user_id, meta_key, meta_value)
VALUES ('user_id', 'wp_s2member_auto_eot_time', 1366286009),
('user_id', 'wp_s2member_paid_registration_times', 'a:2:{s:5:"level";s:10:"1366285409";s:6:"level1";s:10:"1366285409";}');
First statement will return list of user_id's which can be rather long. 第一条语句将返回user_id的列表,该列表可能会很长。 I'd like for EACH of these id's INSERT to add respective 2 rows.
我想为每个这些ID的INSERT分别添加2行。
I could probably write a php script to do the same, put first list in an array and than do for and run every INSERT using php. 我可能可以编写一个php脚本来执行相同的操作,将第一个列表放入数组中,然后使用php来运行每个INSERT。 But I'd like to learn a bit more about sql.
但是我想了解更多有关sql的知识。 Is it possible what I'm trying to achieve?
我有可能实现什么目标?
Does your table wp_usermeta have any other columns? 您的表wp_usermeta是否还有其他列? Does it have a primary key or some other index?
它有主键还是其他索引?
(I'm sorry about asking for clarification in an "answer", but the system does not let me add comments to other people's question - yet. As soon as you add some clarification, I will revise this "answer" to be actual answer to your question.) (对于要在“答案”中进行澄清,我们感到抱歉,但是系统尚未允许我在其他人的问题上添加注释-。一旦您添加了一些澄清,我就会将此“答案”修改为实际答案您的问题。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.