MYSQL INSERT SELECT problem(MYSQL INSERT SELECT 问题)
问题描述
我在理解如何执行某些 INSERT SELECT 方面有点困难.
i have a little difficulty in understanding how to do some INSERT SELECT.
例如我有两张桌子.
TABLE : users
id | name | gender
1 | John | m
2 | Mary | f
TABLE : website
fid | url | id
1 | www.desilva.biz | 2
2 | gidhelp.com | 4
现在假设我想向表格网站添加另一个查询.我得到两个变量,让我们说:
Now let's say i want to add another query to the table website. I get two variables, lets say:
$user = John;
$site = "www.google.com";
我想从 users 表中选择 John 的 id 并在一个语句中将其插入到 website 表中.
i want to select the id of John from users table and insert it into website table in one statement.
我该怎么做?
推荐答案
假设你的变量已经被正确转义并且不受SQL注入的影响:
Assuming your variables are already escaped properly and are not subject to SQL injection:
INSERT
INTO website (url, fid)
SELECT $site, id
FROM users
WHERE name = $user
这篇关于MYSQL INSERT SELECT 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MYSQL INSERT SELECT 问题
基础教程推荐
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在多列上分布任意行 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
