PDA

View Full Version : Merging Queries


KGodel
04-22-2014, 01:08 AM
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.

$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.