INSERT and SELECT how can I do this.

This is a discussion on INSERT and SELECT how can I do this. within the MySQL Database forums, part of the Database Forums category; Hi, I'm trying to insert a value from a second table into a new table using INSERT and SELECT, ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-02-2007
Alogen
 
Posts: n/a
Default INSERT and SELECT how can I do this.

Hi,
I'm trying to insert a value from a second table into a new table using
INSERT and SELECT, this is the way I 'm trying to build my querie but does
not work.
Using MySql 4.0.x and MyPHPAdministrator.


INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
((SELECT `Table2field` FROM `Table2`
WHERE `fieldname` = `category`), 'Book1')

INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
((SELECT `Table2field` FROM `Table2`
WHERE `fieldname` = `category`), 'Book2')

INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
((SELECT `Table2field` FROM `Table2`
WHERE `fieldname` = `category`), 'Book3')


Reply With Quote
  #2 (permalink)  
Old 09-02-2007
Rik Wasmus
 
Posts: n/a
Default Re: INSERT and SELECT how can I do this.

On Sun, 02 Sep 2007 18:27:59 +0200, Alogen <myemail@mysite.us> wrote:

> Hi,
> I'm trying to insert a value from a second table into a new table using
> INSERT and SELECT, this is the way I 'm trying to build my querie but
> does
> not work.
> Using MySql 4.0.x and MyPHPAdministrator.
>
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book1')
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book2')
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book3')


INSERT INTO `Table1` (`field1`, `field2`)
SELECT `Table2field`,'Book1' FROM `Table2`
WHERE `fieldname` = `category`

--
Rik Wasmus
Reply With Quote
  #3 (permalink)  
Old 09-02-2007
Paul Lautman
 
Posts: n/a
Default Re: INSERT and SELECT how can I do this.

Alogen wrote:
> Hi,
> I'm trying to insert a value from a second table into a new table
> using INSERT and SELECT, this is the way I 'm trying to build my
> querie but does not work.
> Using MySql 4.0.x and MyPHPAdministrator.
>
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book1')
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book2')
>
> INSERT INTO `Table1` (`fiel1`, `field2`) VALUES
> ((SELECT `Table2field` FROM `Table2`
> WHERE `fieldname` = `category`), 'Book3')


In cases like this it is always a good idea to follow the syntax as
published in the manual rather than making up your own!

http://dev.mysql.com/doc/refman/4.1/en/insert.html


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 09:19 AM.


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