The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
MyChenQL, part III
How do I combine these queries into one?
[sql] UPDATE forum SET something = "value1" WHERE forumid=first UPDATE forum SET something = "value2" WHERE forumid=second UPDATE forum SET something = "value3" WHERE forumid=third . . . [/sql] |
#2
|
||||
|
||||
hmm, not sure if it's possible, but if then i'd say with this query:
[sql]UPDATE forum SET something = IF(forumid=first,"value1",IF(forumid=second,"value 2", "value3")) WHERE forumid IN (first, second, third)[/sql] but i really not sure if it works... i just can say it doesn't look good |
#3
|
|||
|
|||
So the only two options are to make one incredibly complex query or to *dramatic music* query in a loop?
|
#4
|
||||
|
||||
yes i think so....
|
#5
|
|||
|
|||
Which one would be preferable, then?
|
#6
|
||||
|
||||
depends on what you want.
faster should be the if-way (if it really works ) but nicer is the reapeated while. if it wouldn't produce too much queries on an often called page, i'd use the while-method. if it's an page where it's important of how much queries are on, i'd use the if method, but code it better readable in a half while or recursive method to get the querystring |
#7
|
|||
|
|||
Here you go what you wanted:
UPDATE forum AS f1, forum AS f2, forum AS f3 SET f1.something = "value1", f2.something = "value2", f2.something = "value3" WHERE f1.forumid=first AND f2.forumid=second AND f3.forumid=third; |
#8
|
|||
|
|||
Now these queries won't be incredibly server-intensive, will be?
I find it hard to believe that MySQL doesn't have this built in |
#9
|
|||
|
|||
just use
EXPLAIN whatever your query is so EXPLAIN SELECT * FROM user WHERE username='person'; |
#10
|
||||
|
||||
Codename&PPN: Everyday you can learn something new
thx |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|