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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:17:46+00:00 2026-05-25T13:17:46+00:00

Below query is doing what I need: SELECT assign.from_uid, assign.aid, assign.message, curriculum.asset, curriculum.title, curriculum.description

  • 0

Below query is doing what I need:

SELECT assign.from_uid, assign.aid, assign.message, curriculum.asset, 
       curriculum.title, curriculum.description 
FROM assignment assign 
INNER JOIN curriculum_topics_assets curriculum 
   ON assign.nid = curriculum.asset 
WHERE assign.to_uid = 13 AND assign.status = 1 
GROUP BY assign.from_uid, assign.to_uid, assign.nid 
ORDER BY assign.created DESC

Now I need to get the total count of rows of the result. For example if it is displaying 5 rows the o/p should be like My expected o/p. The query I tried is given below.

SELECT count(description) FROM assignment assign 
INNER JOIN curriculum_topics_assets curriculum ON assign.nid = curriculum.asset 
WHERE assign.to_uid = 13 AND assign.status = 1 
GROUP BY assign.from_uid, assign.to_uid, assign.nid 
ORDER BY assign.created DESC

My expected o/p:

count(*)
---------
5

My current o/p:

count(*)
---------
6
2
5
6
6
  • 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-25T13:17:47+00:00Added an answer on May 25, 2026 at 1:17 pm

    The easiest solution would be to

    • place your initial GROUP BY query in a subselect
    • select the amount of rows retrieved from this subselect

    SQL Statement

    SELECT COUNT(*)
    FROM   (
              SELECT  assign.from_uid 
              FROM    assignment assign 
                      INNER JOIN curriculum_topics_assets curriculum ON assign.nid = curriculum.asset 
              WHERE   assign.to_uid = 13 
                      AND assign.status = 1 
              GROUP BY 
                      assign.from_uid
                      , assign.to_uid
                      , assign.nid 
           ) q
    

    Edit – why doesn’t the original query return the results required

    It did already prepared what was needed to get the correct result

    1. Your query without grouping returns a resultset of 25 records (6+2+5+6+6)
    2. From these 25 records, you have 5 unique combinations of from_uid, to_uid, nid

    Now you don’t want to count how many records each combination has (as you did in your example) but how many unique (distinct anyone?) combinations there are.

    One solution to this is the subselect I presented but following equivalent statement using a DISTINCT clause might be more comprehensive.

    SELECT  COUNT(*)
    FROM    (
              SELECT  DISTINCT assign.from_uid
                      , assign.to_uid
                      , assign.nid
              FROM    assignment assign 
                      INNER JOIN curriculum_topics_assets curriculum ON assign.nid = curriculum.asset 
              WHERE   assign.to_uid = 13 
                      AND assign.status = 1 
            ) q
    

    Note that my personal preference goes to the GROUP BY solution.

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

Sidebar

Related Questions

I have the below query in a postgresql database SELECT * FROM accounts where
I run the below query..... SELECT SUM(PAPostedTotalCostN) AS Total_Cost FROM PA01201 WHERE PA01201.PAcontid =
What does the below query explain? SELECT * FROM `jos_menu` WHERE (id = 69
I am trying to extract the below query: select '<tr><td>'||column1||'</td>', '<td>'||column2||'</td>', '<td>'||column3||'</td></tr>' from table
I would need to get an average from the below linq query but the
I came up with the below query: SELECT ROOMNO,BUILDINGNO FROM MRM_ROOM_DETAILS WHERE ROOMID IN
I am doing project in cakephp . I want to write below query in
I have below query I am trying to show message 'No SubSource for this
I have the below Linq query that is returning the data but I need
I have a SP with 20 select queries. Each query is table-name-aliased like below.

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.