使用sql查询插入数据的问题

使用sql查询插入数据的问题

本文介绍了使用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 [email protected]')





查询没有错误,但是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='[email protected]'))


insert into missinginfo ( mfname,mlname,id) select 'john','wilson',id from account where username='[email protected]'


insert into missinginfo ( mfname,mlname,id) values ('john','wilson', select id from account where [email protected])





修正/>



correction after reading solution #1 from KARTHIK

insert into missinginfo ( mfname,mlname,id) values ('john','wilson', (select id from account where [email protected]))







而不是


这篇关于使用sql查询插入数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:57