vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   MyChenQL, part III (https://vborg.vbsupport.ru/showthread.php?t=46676)

filburt1 12-14-2002 08:58 PM

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]

Xenon 12-14-2002 10:23 PM

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 ;)

filburt1 12-15-2002 12:14 AM

So the only two options are to make one incredibly complex query or to *dramatic music* query in a loop?

Xenon 12-15-2002 11:56 AM

yes i think so....

filburt1 12-15-2002 02:00 PM

Which one would be preferable, then?

Xenon 12-15-2002 03:03 PM

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 :)

okrogius 12-16-2002 01:11 AM

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;

filburt1 12-16-2002 01:18 AM

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 :(

Scott MacVicar 12-16-2002 06:46 AM

just use

EXPLAIN whatever your query is
so
EXPLAIN SELECT * FROM user WHERE username='person';

Xenon 12-16-2002 02:38 PM

Codename&PPN: Everyday you can learn something new :)
thx :)


All times are GMT. The time now is 03:03 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
  • Page Generation 0.01083 seconds
  • Memory Usage 1,722KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete