dongli7870 2015-07-28 09:32
浏览 107
已采纳

SQL插入ID,加上静态字符串

I've had a look around but I can't quite seem to find what I'm looking for. I know this is probably completely wrong and the answer is most likely something simple, but I can't work it out. I'm still quite new to MySQL queries so any help would be fantastic.

I have this

INSERT INTO bitnami_wordpress.wp_usermeta_new (user_id, meta_key, meta_value)
SELECT `UserID`, VALUE(`phone_number`),`telephone_number`
FROM my_db.userinfo

As you can see, I have a VALUE there. I'm trying to make that part a static string to be inserted into 'meta_key', so that it is placed something like

user_id - meta_key     - meta_Value
1       - phone_number - 01234567890
1       - fav_colour   - red

So the user_id and telephone_number are brought from the table, but the VALUE is a static piece of text. I'm basically trying to convert a table to WP via several MySQL queries in PHPMyAdmin. I'll be doing the same thing for several other fields such as fav_colour (just an example).

  • 写回答

1条回答 默认 最新

  • douquan1015 2015-07-28 09:35
    关注

    You query should look like:

    INSERT INTO bitnami_wordpress.wp_usermeta_new (user_id, meta_key, meta_value)
    SELECT `UserID`, 'phone_number',`telephone_number`
    FROM my_db.userinfo
    

    You only need single quotes arround the static string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?