简体   繁体   English

Mysql选择user_ID并使用这些来构造INSERT语句,可能吗?

[英]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.

相关问题 如何将日期和user_id插入mysql - How to insert date and user_id to mysql 如果 select 行在 MySQL 中有超过 1 行的列值(状态:“活动”),是否可以通过 1 列值(user_id) - Is it possible to select rows by 1 column value(user_id) if it have more then 1 rows with column value(status: "active") in MySQL CODEIGNITER如何在登录user_ID时将user_ID插入mySQL - CODEIGNITER how to insert user_ID to mySQL when that user_ID is logged in MySQL-根据具有相同user_id的其他行的列值,按user_id选择行 - MySQL - select row by user_id based on column value of other rows with the same user_id PHP的; mysql;如何插入user_id或date_created? - php; mysql;How to insert user_id or date_created? MySQL - SELECT IN - 计算结果中user_id的行数? - MySQL - SELECT IN - Counting the # of rows for a user_id in a result? MySQL-每个日期每个user_id的SELECT MIN时间 - MySQL - SELECT MIN time per user_id per date MySQL选择不重复并确定是否只有一个user_id - MySQL select distinct and determine if only one user_id exists 我应该使用user_id(主键)还是user_name(唯一索引)从MySQL插入和获取数据 - Should I use user_id (Primary Key) or user_name (Unique Index) To Insert and Fetch Data From Mysql INSERT…SELECT语句的mysql_insert_id() - mysql_insert_id() for INSERT…SELECT statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM