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 6189773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:28:18+00:00 2026-05-24T02:28:18+00:00

What I have are two tables: mark_notifications mark_notifications_options The mark_notifications table contains rows of

  • 0

What I have are two tables:

mark_notifications

mark_notifications_options

The mark_notifications table contains rows of data that include a column tid and userid

The mark_notifications_options table contains a special column grouptogether

What I am trying to achieve is that if the userid’s mark_notifications_options.grouptogether value is set to 0, it will add up every row that matches his userid in the mark_notifications table

However, if the userid’s mark_notifications_options.grouptogether value is set to 1, it will add up every row that matches his userid where all the tids are grouped, so that if there no matter how many times the same tid value comes up, it only gets counted as 1. I also would like to count the times tid = 0 as a separate entitiy (but NOT grouped) and then I would just add the values later in php.

This is what I have come up with so far, but the resulting values dont make any sense at all, im getting results that number in the thousands (when it should be a low number like 8 for example).

SELECT 
         mark_notifications_options.grouptogether,
         COUNT(mark_notifications.threadid) AS ungrouped, 
         SUM(mark_notifications.threadid = 0) AS total_zero, 
         COUNT(DISTINCT mark_notifications.threadid) AS grouped 
    FROM mark_notifications, mark_notifications_options
   WHERE mark_notifications.userid = $userid
GROUP BY mark_notifications_options.grouptogether

Thanks!!!

  • 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-24T02:28:18+00:00Added an answer on May 24, 2026 at 2:28 am

    You were missing a join predicate, and so were getting the cartesian product (ie resulting in n x n rows).
    Try this:

    SELECT 
             mark_notifications_options.grouptogether,
             COUNT(mark_notifications.threadid) AS ungrouped, 
             SUM(mark_notifications.threadid = 0) AS total_zero, 
             COUNT(DISTINCT mark_notifications.threadid) AS grouped 
        FROM mark_notifications mark_notifications
        LEFT JOIN mark_notifications_options mark_notifications_options on mark_notifications_options.userid = mark_notifications.userid
       WHERE mark_notifications.userid = $userid
    GROUP BY mark_notifications_options.grouptogether
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables. One table contains information about Assets, another Table about their
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables connected with one to many relationship. Parent Table is a
I have two tables: users and user_depts. Let's say (for this question) that users
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE

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.