使用sql查询插入数据的问题 [英] Problem with inserting the data using sql query
本文介绍了使用sql查询插入数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表,一个是帐户表,另一个是missinginfo表。
我想将帐户表中的id列插入到缺少的信息表中..
这是我的查询
I have two tables one is account table and the another is missinginfo table.
I want to insert the id column from the account table to the missing info table..
here is my query
insert into missinginfo ( mfname,mlname,id) values ('john','wilson', 'select id from account where username=abc@abc.com')
查询没有错误,但是id列给出错误的结果即0 ..
问题出在哪里..
Query gives no error but the id column give wrong result i.e 0 ..
where is the problem..
推荐答案
insert into missinginfo ( mfname,mlname,id) values ('john','wilson', (select id from account where username='abc@abc.com'))
您的插入查询错误。
检查下面的tsql查询。
Your insert query is wrong.
Check below tsql query.
insert into missinginfo ( mfname,mlname,id) select 'john','wilson',id from account where username='abc@abc.com'
从id-sql中删除单引号
喜欢这个
Remove the single quotes from the id-sql
like this
insert into missinginfo ( mfname,mlname,id) values ('john','wilson', select id from account where username=abc@abc.com)
修正/>
correction after reading solution #1 from KARTHIK
insert into missinginfo ( mfname,mlname,id) values ('john','wilson', (select id from account where username=abc@abc.com))
而不是
and not like
insert into missinginfo ( mfname,mlname,id) values ('john','wilson', 'select id from account where username=abc@abc.com')
这篇关于使用sql查询插入数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文