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, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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') |
|
|||
|
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 |
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|