467,894 Members | 1,436 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Tricky INSERT

I have table A with column id, and table B with columns id and
content.

I am trying to build a query that inserts all ids from table A into
table B, and also sets the "value" field for all these new entries to
a given value.
For example:
#Before the query, the tables are like this:
mysql> select * from a;
+------+
| id |
+------+
| hal |
| ron |
| kip |
| dag |
| bob |
| max |
+------+

mysql> select * from b;
+------+-------+
| id | value |
+------+-------+
| bob | 4 |
| bob | 5 |
| max | 5 |
+------+-------+

# After the query, b is like this:

mysql> select * from b;
+------+-------+
| id | value |
+------+-------+
| bob | 4 |
| bob | 5 |
| dag | 4 |
| hal | 4 |
| kip | 4 |
| max | 4 |
| max | 5 |
| ron | 4 |
+------+-------+

I have been trying variations on the INSERT ... SELECT syntax, but
I suspect this is a dead end. The next best thing I can think
of is building a temporary table that has the values that I want, and
then using INSERT ... SELECT to copy them all into table b.

Can anyone suggest a way to achieve this?
--Fraser Hanson

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
  • viewed: 1341
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Joel Thornton | last post: by
3 posts views Thread by Martin | last post: by
19 posts views Thread by Kai-Uwe Bux | last post: by
5 posts views Thread by scott | last post: by
5 posts views Thread by Johnny Ljunggren | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.