Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inserting new records from a select

4 views
Skip to first unread message

Nene

unread,
Apr 30, 2012, 9:50:28 PM4/30/12
to
I need to do a 'select * from <TABLE> where BLAH = 'node_one' and
insert the results into new records containing identical information
except that it will say node_two, instead of node_one. I don't want to
replace but add records.

For example:

Here's the results of my select:

| 27 | 1 | | node_one | 7503 |
xxxxx |
| 37 | 0 | | node_one | 7000 |
xxxxxxxxx |
| 55 | 1 | | node_one | 7502 |
xxxxxxxx |
| 64 | 1 | | node_one | 7001 |
xxxxxxxxx |
| 71 | 1 | | node_one | 7726 |
xxxxxxxxxxx |
| 113 | 1 | | node_one | 7505 |
xxxxxxxxxxxxxxxxxxxxxxxxxx |
| 377 | 1 | | node_one | 6266 |
xxxxxxxxx |

Insert the above and make it look like below:

| xx | 1 | | node_two | 7503 |
xxxxx |
| xx | 0 | | node_two | 7000 |
xxxxxxxxx |
| xx | 1 | | node_two | 7502 |
xxxxxxxx |
| xx | 1 | | node_two | 7001 |
xxxxxxxxx |
| xx | 1 | | node_two | 7726 |
xxxxxxxxxxx |
| xx | 1 | | node_two | 7505 |
xxxxxxxxxxxxxxxxxxxxxxxxxx |
| xx | 1 | | node_two | 6266 |
xxxxxxxxx |

***By the way the first columm (xx) is the primary key***

Thanks in advance...

Rod

Jerry Stuckle

unread,
Apr 30, 2012, 10:06:55 PM4/30/12
to
Something like 'INSERT INTO tbl2 (col1, col2, col3, col4, col5, col6)
VALUES (SELECT col1, col2, col3, 'node_two', col5, col6 FROM tbl2);

Assuming there are no other restraints, etc. you haven't told us about.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

"Álvaro G. Vicario"

unread,
May 3, 2012, 3:42:43 AM5/3/12
to
El 01/05/2012 3:50, Nene escribió/wrote:
> I need to do a 'select * from<TABLE> where BLAH = 'node_one' and
> insert the results into new records containing identical information
> except that it will say node_two, instead of node_one. I don't want to
> replace but add records.

Just do a combined SELECT+INSERT:

http://dev.mysql.com/doc/refman/5.5/en/insert-select.html


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
0 new messages