MySQL INSERT 按照文档正常工作 [英] MySQL INSERT working properly as documented

查看:39
本文介绍了MySQL INSERT 按照文档正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是我有一个名为 m_select 的表,它有四个字段 --> id, id_m, hello, bye .. 我想从脚本中的变量中获取其中两个字段,即 id 和 id_m 以及使用 SELECT 来自名为 test1 的不同表中的两个......是可能的.

What im trying to do is I have an Table called m_select which has four fields --> id, id_m, hello, bye .. two of those fields i want to get from variables in the script which are id and id_m and two of those from a different table called test1 using SELECT ... IS that possible.

mysql_query("INSERT INTO m_select [(id, id_m, hello, bye)] VALUES [('$U','$$t_id')] SELECT hello,bye FROM test1 [WHERE id='$test_id']");

推荐答案

试试这个:

mysql_query("
  INSERT INTO
    m_select
    (id, id_m, hello, bye)
   SELECT
     '$U' AS id,
     '$$t_id' AS id_m,
     hello,
     bye
   FROM test1 WHERE id='$test_id'
");

我不确定 $$t_id(而不是 $t_id)上的双元符号是否是故意的,但我想我会至少让你意识到它.

I'm not sure whether the double-dollar sign on $$t_id (rather than $t_id) is intentional or not, but I thought I'd at least make you aware of it.

这篇关于MySQL INSERT 按照文档正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆