vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Merging Queries (https://vborg.vbsupport.ru/showthread.php?t=310664)

KGodel 04-22-2014 01:08 AM

Merging Queries
 
Hello everyone!

As I am still learning MySQL and proper syntax, I am having some trouble. Currently, I have the follow four queries. For simplicity's sake, I'd like to merge them as one query, however my results from searching online haven't been very helpful, and I was hoping someone could help me out here.

PHP Code:

$threads_q $db->query_read_slave("SELECT COUNT(*) FROM " TABLE_PREFIX "thread WHERE postuserid = $userid AND forumid NOT IN (13, 19, 28, 43, 47, 49, 71, 86, 126, 141,162, 167, 168, 178, 180, 181, 219, 222, 233, 237, 238, 239, 243, 254, 255, 256, 259, 267, 284, 285, 287, 301, 304, 306, 307, 312, 313, 314, 316, 319, 337, 338, 345, 346, 375, 381, 384, 385, 391, 396)");
$recruits_q $db->query_read_slave("SELECT COUNT(*) FROM " TABLE_PREFIX "user WHERE referrerid = $userid");
$awards_q $db->query_read_slave("SELECT COUNT(*) FROM " TABLE_PREFIX "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20)");
$info_q $db->query_read_slave("SELECT username, posts, joindate FROM " TABLE_PREFIX "user WHERE userid = $userid"); 

It should be pretty easy what I am counting in the count queries. ANy advice on how to merge these into one query?

kh99 04-22-2014 09:57 PM

I'm not an SQL expert or anything, but I don't see how you could combine them. You're using 3 different tables, and although you're using the user table in 2 of them, you're doing 2 completely different queries.


All times are GMT. The time now is 11:21 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.02312 seconds
  • Memory Usage 1,714KB
  • 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)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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