Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to join two tables without messing up the query
    primarykey
    data
    text
    <p>I have this query for example (good, it works how I want it to)</p> <pre><code>SELECT `discusComments`.`memberID`, COUNT( `discusComments`.`memberID`) AS postcount FROM `discusComments` GROUP BY `discusComments`.`memberID` ORDER BY postcount DESC </code></pre> <p>Example Results:</p> <pre><code>memberid postcount 3 283 6 230 9 198 </code></pre> <p>Now I want to join the memberid of the discusComments table with that of the discusTopic table (because what I really want to do is only get my results from a specific GROUP, and the group id is only in the topic table and not in the comment one hence the join.</p> <pre><code>SELECT `discusComments`.`memberID`, COUNT( `discusComments`.`memberID`) AS postcount FROM `discusComments` LEFT JOIN `discusTopics` ON `discusComments`.`memberID` = `discusTopics`.`memberID` GROUP BY `discusComments`.`memberID` ORDER BY postcount DESC </code></pre> <p>Example Results:</p> <pre><code>memberid postcount 3 14789 6 8678 9 6987 </code></pre> <p>How can I stop this huge increase happening in the postcount? I need to preserve it as before.</p> <p>Once I have this sorted I want to have some kind of line which says <code>WHERE discusTopics.groupID = 6</code>, for example</p> <pre><code>CREATE TABLE IF NOT EXISTS `discusComments` ( `id` bigint(255) NOT NULL auto_increment, `topicID` bigint(255) NOT NULL, `comment` text NOT NULL, `timeStamp` bigint(12) NOT NULL, `memberID` bigint(255) NOT NULL, `thumbsUp` int(15) NOT NULL default '0', `thumbsDown` int(15) NOT NULL default '0', `status` int(1) NOT NULL default '1', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7190 ; </code></pre> <p>.</p> <pre><code>CREATE TABLE IF NOT EXISTS `discusTopics` ( `id` bigint(255) NOT NULL auto_increment, `groupID` bigint(255) NOT NULL, `memberID` bigint(255) NOT NULL, `name` varchar(255) NOT NULL, `views` bigint(255) NOT NULL default '0', `lastUpdated` bigint(10) NOT NULL, PRIMARY KEY (`id`), KEY `groupID` (`groupID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=913 ; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload