insert constant with list from select

This is a discussion on insert constant with list from select within the MySQL Database forums, part of the Database Forums category; Hi I am trying to insert into a table a bunch of rows from a select and a constant. I ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008
mcardeiro@yahoo.com
 
Posts: n/a
Default insert constant with list from select

Hi

I am trying to insert into a table a bunch of rows from a select and a
constant. I tried this which seems like it should work:

INSERT INTO workgroupUsers VALUES( SELECT 280, username FROM
workgroupUsers WHERE id = 278);


is this because I am selecting from the same table I am updating? or
is it not possible to achieve what I am trying


Mike Cardeiro
Reply With Quote
  #2 (permalink)  
Old 02-26-2008
Captain Paralytic
 
Posts: n/a
Default Re: insert constant with list from select

On 26 Feb, 16:49, "mcarde...@yahoo.com" <mcarde...@yahoo.com> wrote:
> Hi
>
> I am trying to insert into a table a bunch of rows from a select and a
> constant. I tried this which seems like it should work:
>
> INSERT INTO workgroupUsers VALUES( SELECT 280, username FROM
> workgroupUsers WHERE id = 278);
>
> is this because I am selecting from the same table I am updating? or
> is it not possible to achieve what I am trying
>
> Mike Cardeiro


You need to use the INSERT SELECT syntax as specified in the manual.
You can't just make up your own syntax.
Reply With Quote
  #3 (permalink)  
Old 02-27-2008
ThanksButNo
 
Posts: n/a
Default Re: insert constant with list from select

On Feb 26, 8:49 am, "mcarde...@yahoo.com" <mcarde...@yahoo.com> wrote:
> Hi
>
> I am trying to insert into a table a bunch of rows from a select and a
> constant. I tried this which seems like it should work:
>
> INSERT INTO workgroupUsers VALUES( SELECT 280, username FROM
> workgroupUsers WHERE id = 278);
>


INSERT INTO workgroupUsers (id, username)
SELECT 280, username
FROM workgroupUsers
WHERE id = 278

And - - - follow Captain Paralytic's sound advice
Reply With Quote
  #4 (permalink)  
Old 02-27-2008
mcardeiro@yahoo.com
 
Posts: n/a
Default Re: insert constant with list from select

Thanks Cap'n and ThanksButNo

-Mike
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:01 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0