|
 |
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
|
|
09-24-2012, 04:20 PM
|
PM User |
#1
|
|
Regular Coder
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
|
INSERT Rows where userid=(SELECT id FROM userinfo)
Hello I'm trying to do something like this
Code:
INSERT INTO VotingSite (VotingSiteType, active) VALUES ('10', 0) WHERE userid=(SELECT ID FROM userinfo)
Doesn't work any ideas?
It's suppose to add a row with the userid
|
|
|
|
09-24-2012, 09:12 PM
|
PM User |
#2
|
|
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
|
You can't use WHERE in INSERT.
Period.
Show us what fields you have in the VotingSite table.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
|
|
|
09-24-2012, 09:54 PM
|
PM User |
#3
|
|
Regular Coder
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
|
http://gyazo.com/9422820f30a3f8c7c6f03d04c1e92f26
Each user has 11 rows to themselves which is are sites. But when we add a new site into the program we need to add a new row for every user
ID USERID VOTINGSITETYPE ACTIVE
How can I dynamically add a new row for every user in Users table
|
|
|
09-24-2012, 11:44 PM
|
PM User |
#4
|
|
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
|
Ahhh...got it.
Code:
INSERT INTO VotingSite (userid, VotingSiteType, active)
SELECT ID, 10, 0 FROM userinfo
See that? You can SELECT both fields *AND CONSTANT VALUES* from a table, so combine that with INSERT INTO and you are done.
NOTE: Don't put apostrophes around numeric values ('10' in your example) unless the data type in question really is a string type.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
|
|
|
09-25-2012, 02:25 AM
|
PM User |
#5
|
|
Regular Coder
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
|
Thanks, looked like it worked!
|
|
|
10-09-2012, 06:09 AM
|
PM User |
#6
|
|
New Coder
Join Date: Sep 2012
Location: USA
Posts: 13
Thanks: 0
Thanked 2 Times in 2 Posts
|
Insert Rows where userid=(select id from userinfo)
Hi ! INSERT INTO VotingSite (userid, VotingSiteType, active)
SELECT UID, 30, 1 FROM userinfo
I think this will work.
|
|
|
10-09-2012, 04:05 PM
|
PM User |
#7
|
|
Super Moderator

Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
|
Quote:
Originally Posted by JefferyJamison
Hi ! INSERT INTO VotingSite (userid, VotingSiteType, active)
SELECT UID, 30, 1 FROM userinfo
I think this will work. 
|
Yes that will work. If you read the thread closely, you'll see that solution was given and verified two weeks ago though.
|
|
|
10-09-2012, 08:23 PM
|
PM User |
#8
|
|
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
|
Quote:
Originally Posted by JefferyJamison
Hi ! INSERT INTO VotingSite (userid, VotingSiteType, active)
SELECT UID, 30, 1 FROM userinfo
I think this will work. 
|
Actually, no it won't work. If you look carefully at the first post, the field name in the userinfo table is ID
No idea where you came up with UID but it's plain flat wrong.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
|
|
|
 |
Jump To Top of Thread
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 01:55 PM.
|
Advertisement Log in to turn off these ads. |
|
|
|
|
|
|
|
|
|
|