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 - `employee` and `department`. 1. `employee` table contains column id,employee
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables, like so: table a contains: id|name stock1|fullname stock2|fullname2 stock3|fullname3 table
I have two tables that look as Follows: Person (Table Name) Name1/Phone1/Email1/Address1/Organization1/Notes1 (Fields) Organization
I have two tables: Accounts , which contains the information of accounts that a
I have two tables that are joined together. A has many B Normally you
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables, one parent and one child table. Child will have many
I have two tables, that share the same definition. I commonly insert new objects

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.