sorry for the unspecific title, but my english is not the best.
My problem is, that I have one Table with say an id and a category field named v2_dl
and I have another table with an id, an v2_dl_id
and a category field named v2_dl_search
.
And one row from v2_dl has many rows from v2_dl_search belonging to it.
Now I want to set every v2_dl_search.category value to the value of its belonging v2_dl row. (Just for one specific value for category)
I wrote a Script in Php to do ist, but the while loop does around 1k querys, and that seems a little bit to much for the server.
$dls = db_query("SELECT id FROM v2_dl WHERE category = '3'");
while($dl = mysql_fetch_arra开发者_StackOverflow社区y($dls)){
db_query("UPDATE v2_dl_search SET category = '3' WHERE id = '".$dl['id']."'");
is there a better way to do this with only sql?
Sorry for the poor language and explanation.
For a specific category, you want to do this:
db_query("UPDATE v2_dl_search SET category = '3' WHERE v2_dl_id in (select v2_dl_id from v2_dl where category = '3')");
For all categories:
db_query("UPDATE v2_dl_search SET category = (select category from v2_dl where v2_dl_search.v2_dl_id = v2_dl.v2_dl_id)");
精彩评论