user967451
user967451

Reputation:

Better way to do this MySQL query?

This is what I'm doing now, how to do this without resorting to a subquery and without the php. I can just run it inside phpmyadmin directly:

   <?php

    $query = mysql_query(" SELECT node_id FROM embeds ");
    while($row = mysql_fetch_assoc($query)) {
        $node_id = $row['node_id'];
        mysql_query(" INSERT INTO node_teaser(node_id, content) VALUES('$node_id', 'This is the teaser!') ");
    }

    ?>

Upvotes: 1

Views: 28

Answers (1)

a1ex07
a1ex07

Reputation: 37364

INSERT INTO node_teaser(node_id, content)
SELECT node_id, 'This is the teaser!' FROM embeds;

Upvotes: 3

Related Questions