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

Chris M 12-16-2002 03:12 PM

Cool:)

Satan

filburt1 12-16-2002 04:33 PM

Quote:

Originally posted by Codename49
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;

Not working:

Quote:

Database error in vBulletin 2.2.9:

Invalid SQL: UPDATE forum AS f0, forum AS f1, forum AS f2, forum AS f3, forum AS f4, forum AS f5, forum AS f6, forum AS f7, forum AS f8, forum AS f9, forum AS f10, forum AS f11, forum AS f12, forum AS f13, forum AS f14, forum AS f15, forum AS f16, forum AS f17, forum AS f18, forum AS f19, forum AS f20, forum AS f21, forum AS f22, forum AS f23, forum AS f24, forum AS f25, forum AS f26, forum AS f27, forum AS f28, forum AS f29, forum AS f30, forum AS f31, forum AS f32, forum AS f33, forum AS f34, forum AS f35 SET f0.lastthreadtitle = 'Layout and Quicktime issu...', f1.lastthreadtitle = 'Use A String Value From W...', f2.lastthreadtitle = 'Save as target..more info', f3.lastthreadtitle = 'Feedback', f4.lastthreadtitle = 'help me.', f5.lastthreadtitle = 'Am doing some research on...', f6.lastthreadtitle = 'Cool web-editor...', f7.lastthreadtitle = 'Member of the Month (Octo...', f8.lastthreadtitle = 'Need new Vid Card...', f9.lastthreadtitle = 'Have fun :)', f10.lastthreadtitle = '...and now Chit Chat is o...', f11.lastthreadtitle = 'I M IN A BAD MOOD! I WANT...', f12.lastthreadtitle = 'MSN! GRR!', f13.lastthreadtitle = 'Notating Time in a MySQL ...', f14.lastthreadtitle = 'CPU - Computer Power User', f15.lastthreadtitle = 'Scepter 17" moniter', f16.lastthreadtitle = 'Direct Connect Addendum.....', f17.lastthreadtitle = 'Visual Basic: Adding Func...', f18.lastthreadtitle = 'Case Modding Tutorial', f19.lastthreadtitle = 'Hosting Matters', f20.lastthreadtitle = 'Kedaman...your music?', f21.lastthreadtitle = 'Best way to store passwor...', f22.lastthreadtitle = 'DEADNESS!', f23.lastthreadtitle = 'Eminem - The Eminem Story', f24.lastthreadtitle = 'What software do you use?', f25.lastthreadtitle = 'new', f26.lastthreadtitle = 'Navigation bar \ No frame...', f27.lastthreadtitle = 'Wednesday, August 28, 200...', f28.lastthreadtitle = 'WEB DESIGNER/PROMOTER REQ...', f29.lastthreadtitle = 'Make Objects Circular...i...', f30.lastthreadtitle = 'Andy Z!', f31.lastthreadtitle = 'Member of the Month', f32.lastthreadtitle = 'Pages within Pages, step ...', f33.lastthreadtitle = 'Archive of Ripped Sites', f34.lastthreadtitle = 'Hosting Matters', f35.lastthreadtitle = 'Tucows Domain Name Regist...' WHERE f0.forumid = 3 AND f1.forumid = 6 AND f2.forumid = 8 AND f3.forumid = 11 AND f4.forumid = 12 AND f5.forumid = 13 AND f6.forumid = 16 AND f7.forumid = 18 AND f8.forumid = 28 AND f9.forumid = 34 AND f10.forumid = 38 AND f11.forumid = 39 AND f12.forumid = 49 AND f13.forumid = 53 AND f14.forumid = 54 AND f15.forumid = 57 AND f16.forumid = 58 AND f17.forumid = 59 AND f18.forumid = 60 AND f19.forumid = 62 AND f20.forumid = 64 AND f21.forumid = 67 AND f22.forumid = 77 AND f23.forumid = 78 AND f24.forumid = 84 AND f25.forumid = 85 AND f26.forumid = 86 AND f27.forumid = 87 AND f28.forumid = 88 AND f29.forumid = 89 AND f30.forumid = 93 AND f31.forumid = 94 AND f32.forumid = 95 AND f33.forumid = 96 AND f34.forumid = 97 AND f35.forumid = 98
mysql error: You have an error in your SQL syntax near 'AS f0, forum AS f1, forum AS f2, forum AS f3, forum AS f4, forum AS f5, forum AS' at line 1

mysql error number: 1064

Date: Monday 16th of December 2002 01:28:15 PM
Script: http://localhost:8082/web/testvb/rep...adtitlecache=1
Referer:

filburt1 12-16-2002 04:35 PM

I just remembered: you can't update multiple tables at once. So at this rate I'd have to use 36 queries (!) or some other method.

Xenon 12-16-2002 04:42 PM

ahh good to know :)

have you tested my suggestion?
perhaps this works..

filburt1 12-16-2002 04:42 PM

Investigating...

okrogius 12-16-2002 05:18 PM

Ah. I knew this type of query worked wonders on shortening selects but didn't actually test it on an update. Sorry to hear it doesn't work.

filburt1 12-16-2002 05:19 PM

[n00b mode]
XENON YOU'RE A GENIUS!
[/n00b mode]
It worked. The query took relatively long to execute (~1 sec) but this will be a cron'ed script anyway :)

Thanks :D

filburt1 12-16-2002 05:20 PM

Quote:

Originally posted by Codename49
Ah. I knew this type of query worked wonders on shortening selects but didn't actually test it on an update. Sorry to hear it doesn't work.
IIRC multiple tables are supported in MySQL 4 but since practically nobody uses it (including myself) I want to steer clear of it :)

Xenon 12-16-2002 05:22 PM

good to hear it works :)
you're welcome :)

have you compared the running time with the added time of 36 single queries?
i think it's faster :) but don't know exactly..

filburt1 12-16-2002 05:23 PM

It probably is faster but just the concept of using that many is pretty bad IMO.

Xenon 12-16-2002 05:26 PM

think you are right :)
if it's croned it hasn't to be that clear to understand it just must work :)


All times are GMT. The time now is 12:58 AM.

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.01227 seconds
  • Memory Usage 1,755KB
  • 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
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (21)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete