![]() |
Is there a way to set data in multiple records in one query?
In MySQL, is there an efficient way to set a field to a specified list of values in a corresponding list of where conditions (based on the primary key), or do I have to do an individual UPDATE query for each record?
|
Sorry you've totally lost me. Can you perhaps give an example of what you're trying to do :)?
|
you could write a function to do that, but you'd still end up with more queries.
$list[0] = "..."; $list[0] = "..."; $where[0] = "..."; $where[1] = "..."; for($i = 0; $i < sizeof($list); $i++) { mysql_query("UPDATE table SET $list[$i] WHERE $where[$i]"); } |
Quote:
|
With this loop you ARE sending multiple queries.
Better to do like Dean asked and give an examplke of what you try to do. |
Quote:
Quote:
|
Quote:
Also, people are always talking about the cost of a hack in terms of queries, but I can easily construct a query that will take 10 times longer to execute than another. What gives? I hardly believe that the majority of users concerned with such things aren't using mysql as a library, so I don't understand why the number of queries should be more important than the time spent executing them. |
Hmmm, well by the sounds of things what you're doing doesn't sound very efficient either way. As I said before why not tell us exactly what you're trying to do then we can give tips. It's hard to offer advice without an example :)
|
Quote:
Quote:
|
Quote:
|
All times are GMT. The time now is 05:02 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|