Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 532
  • Last Modified:

insert with inner join ?

In Mysql, I want to do an Insert with a where clause indicated by an inner join.

This would be like:

insert into table1 (id,  ts)
INNER JOIN table1  ON (table1.id` = table2.id)
values (1,2)

How can I do this?
0
pillmill
Asked:
pillmill
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Pill,

You need to generate a result set that you select from

INSERT INTO mytable (id, ts)
SELECT (id, t2)
FROM table1
INNER JOIN table2
  ON table1.key = table2.key;


Good Luck,
Kent
0
 
Ray PaseurCommented:
This strikes me as kind of an odd idea.  And I am wondering, "what is the design or business objective?"  

If you want to INSERT INTO table1 a row with id=1 and ts=2, what has table2 got to do with this?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now