Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into Where (syntax help)

Status
Not open for further replies.

theresep

Technical User
Nov 8, 2004
4
US
I am having trouble with the syntax on this;

INSERT INTO t1.mgroup VALUES(11) SELECT FROM members AS t1, moredata AS t2 WHERE t1.id = t2.member_id AND t1.mgroup = 3 AND t2.field_1 ="N"

The objective is that in table Members, I want to insert the number 11 where the member id =3 and the extra data table = "N". The insert and select syntax is challenging to me.

Thanks
 
select what? That's not a valid select statement because you don't have a list of fields.
 
sorry, I am really trying this..

INSERT INTO t1.mgroup VALUES(11) SELECT t1.mgroup,t2.field_1 FROM members AS t1, moredata AS t2 WHERE t1.id = t2.member_id AND t1.mgroup = 3 AND t2.field_1 ="N
 
I think you're trying to do something that you can't or else just making it way more difficult than it should be.

Create a select statement that gets the values you want to insert, then stick "insert into desttable ( list, of, columns, to, insert, into )" in front of it.
 
my select statement works, but my conditional insert isn't working. I must be approaching this wrong.. thanks.
 
There's not such thing as an "insert where" Are you really wanting to do an "update where"?
 
I am going to try UPDATE, but where my confusion must be is that in the MySQL manual, there is a reference to INSERT SELECT WHERE; but there is no VALUE. So maybe I assumed I could use VALUE in the syntax.

Thanks for the tip. I'll also try REPLACE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top