Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 565571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:53:10+00:00 2026-05-13T12:53:10+00:00

Here is my main query which pulls in thread information as one row, it

  • 0

Here is my main query which pulls in thread information as one row, it lacks the # of votes and currently I’m pulling that in with a second query.

SELECT   Group_concat(t.tag_name) AS `tags`,
         `p`.`thread_id`,
         `p`.`thread_name`,
         `p`.`thread_description`,
         `p`.`thread_owner_id`,
         `p`.`thread_view_count`,
         `p`.`thread_reply_count`,
         `p`.`thread_comment_count`,
         `p`.`thread_favorite_count`,
         `p`.`thread_creation_date`,
         `p`.`thread_type_id`,
         `p`.`thread_edited_date`,
         `u`.*,
         `x`.*,
         `t`.*

FROM     `shoop_posts` AS `p`
         INNER JOIN `shoop_users` AS `u`
           ON u.user_id = p.thread_owner_id
         LEFT JOIN `shoop_tags_map` AS `x`
           ON x.thread_id = p.thread_id
         LEFT JOIN `shoop_tags` AS `t`
           ON t.tag_id = x.tag_id


WHERE    (p.thread_id = '1')
GROUP BY `p`.`thread_id` 

My second query which pulls in the # of votes per thread:

SELECT Sum(vote_value)
FROM   shoop_votes
       INNER JOIN shoop_vote_codes
         ON shoop_votes.vote_type = shoop_vote_codes.vote_type
WHERE  thread_id = 1
       AND shoop_votes.vote_type = 3
        OR shoop_votes.vote_type = 2 

A vote type of 2 is an upvote, 3 is a downvote. Here’s the schema if you need it, and some sample data:

CREATE TABLE `shoop_posts` (

  `thread_id` int(11) unsigned NOT NULL auto_increment,

  `thread_name` text,

  `thread_description` text,

  `thread_parent_id` int(11) default NULL,

  `thread_owner_id` int(11) default NULL,

  `thread_view_count` int(11) default NULL,

  `thread_reply_count` int(11) default NULL,

  `thread_comment_count` int(11) default NULL,

  `thread_favorite_count` int(11) default NULL,

  `thread_creation_date` timestamp NULL default NULL,

  `thread_type_id` int(11) default NULL,

  `thread_edited_date` timestamp NULL default NULL,

  PRIMARY KEY  (`thread_id`)

) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;



-- ----------------------------

-- Records of shoop_posts

-- ----------------------------

INSERT INTO `shoop_posts` VALUES ('1', 'Shoop that', '\r\n<img class=\"image-shoop\" src=\"\">\r\n\r\n<p>test:<br>\r\n\r\n\r\n</p>', null, '2', '217', '0', '0', '0', '2010-01-10 02:06:25', '1', null);



-- ----------------------------

-- Table structure for `shoop_tags`

-- ----------------------------


CREATE TABLE `shoop_tags` (

  `tag_id` int(11) NOT NULL auto_increment,

  `tag_name` varchar(11) default NULL,

  PRIMARY KEY  (`tag_id`)

) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;



-- ----------------------------

-- Records of shoop_tags

-- ----------------------------

INSERT INTO `shoop_tags` VALUES ('1', 'mma');

INSERT INTO `shoop_tags` VALUES ('2', 'strikeforce');

INSERT INTO `shoop_tags` VALUES ('3', 'ufc');



-- ----------------------------

-- Table structure for `shoop_tags_map`

-- ----------------------------

DROP TABLE IF EXISTS `shoop_tags_map`;

CREATE TABLE `shoop_tags_map` (

  `map_id` int(11) NOT NULL auto_increment,

  `tag_id` int(11) default NULL,

  `thread_id` int(11) default NULL,

  PRIMARY KEY  (`map_id`)

) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;



-- ----------------------------

-- Records of shoop_tags_map

-- ----------------------------

INSERT INTO `shoop_tags_map` VALUES ('1', '1', '1');

INSERT INTO `shoop_tags_map` VALUES ('2', '2', '2');

INSERT INTO `shoop_tags_map` VALUES ('3', '1', '2');

INSERT INTO `shoop_tags_map` VALUES ('4', '3', '1');

INSERT INTO `shoop_tags_map` VALUES ('5', '3', '2');




-- ----------------------------

-- Table structure for `shoop_vote_codes`

-- ----------------------------


CREATE TABLE `shoop_vote_codes` (

  `vote_type` smallint(1) NOT NULL default '0',

  `vote_value` smallint(2) default NULL,

  PRIMARY KEY  (`vote_type`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;



-- ----------------------------

-- Records of shoop_vote_codes

-- ----------------------------

INSERT INTO `shoop_vote_codes` VALUES ('2', '1');

INSERT INTO `shoop_vote_codes` VALUES ('3', '-1');



-- ----------------------------

-- Table structure for `shoop_votes`

-- ----------------------------

DROP TABLE IF EXISTS `shoop_votes`;

CREATE TABLE `shoop_votes` (

  `thread_id` int(11) NOT NULL default '0',

  `user_id` int(11) NOT NULL default '0',

  `vote_type` smallint(1) NOT NULL default '0',

  PRIMARY KEY  (`thread_id`,`user_id`,`vote_type`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;



-- ----------------------------

-- Records of shoop_votes

-- ----------------------------

INSERT INTO `shoop_votes` VALUES ('1', '1', '2');

INSERT INTO `shoop_votes` VALUES ('1', '2', '2');

INSERT INTO `shoop_votes` VALUES ('1', '3', '3');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:53:10+00:00Added an answer on May 13, 2026 at 12:53 pm

    If I understand you correctly, just using a subquery will do what you’re after:

    SELECT   Group_concat(t.tag_name) AS `tags`,
             `p`.`thread_id`,
             `p`.`thread_name`,
             `p`.`thread_description`,
             `p`.`thread_owner_id`,
             `p`.`thread_view_count`,
             `p`.`thread_reply_count`,
             `p`.`thread_comment_count`,
             `p`.`thread_favorite_count`,
             `p`.`thread_creation_date`,
             `p`.`thread_type_id`,
             `p`.`thread_edited_date`,
             `u`.*,
             `x`.*,
             `t`.*,
             `v`.VoteTotal
    
    FROM     `shoop_posts` AS `p`
             INNER JOIN `shoop_users` AS `u`
               ON u.user_id = p.thread_owner_id
             LEFT JOIN `shoop_tags_map` AS `x`
               ON x.thread_id = p.thread_id
             LEFT JOIN `shoop_tags` AS `t`
               ON t.tag_id = x.tag_id
             LEFT JOIN (SELECT thread_id, Sum(vote_value) as VoteTotal
                        FROM   shoop_votes
                           INNER JOIN shoop_vote_codes
                             ON shoop_votes.vote_type = shoop_vote_codes.vote_type
                        WHERE  shoop_votes.vote_type = 3
                               OR shoop_votes.vote_type = 2
                        GROUP BY thread_id) as `v`
               ON p.thread_id = v.thread_id
    WHERE    (p.thread_id = '1')
    GROUP BY `p`.`thread_id` 
    

    This will let you get all threads as well if you just leave off where last where p.thread_id clause.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you need to create a linked server between the two… May 14, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer I found this article A Recipe to Pretty-Print Your iPhone… May 14, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer Use the insert statement .. INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);… May 14, 2026 at 8:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.