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

  • Home
  • SEARCH
  • 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 8539415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:21:37+00:00 2026-06-11T11:21:37+00:00

Scenario: I have a table named snippets with 5 rows, I have a table

  • 0

Scenario:

I have a table named snippets with 5 rows,
I have a table named revisions with 15 rows

What I wanted to do was get all snippets, which belongs a user_id on revisions, which includes the snippet_id.

I have the following mysql query:

SELECT DISTINCT * FROM "snippets" 
INNER JOIN "revisions" 
    ON "user_id" = "1" 
    AND "snippet_id" = "snippets.id"
GROUP BY "snippets"."id" 
ORDER BY "created_at"

That should display all snippets where revisions.user_id = 1. The problem is, why is my count different? The total results from that query is 5, but when I do:

SELECT COUNT(distinct snippets.id) FROM "snippets" 
INNER JOIN "revisions" 
    ON "user_id" = "1" 
    AND "snippet_id" = "snippets.id"
GROUP BY "snippets"."id";

The result is 1 1 1 1 1

  • 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-06-11T11:21:38+00:00Added an answer on June 11, 2026 at 11:21 am

    There is no meaning for DISTINCT COUNT(*). May be you are looking for COUNT(DISTINCT someotherfield) instead of it. Since COUNT(*) includes any rows that has NULL values.

    Update:* Don’t COUNT the same field that you used in the GROUP BY clause. That is why you are getting the result 1 1 1 1 1. In this case remove the GROUP BY "snippets"."id" clause.

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

Sidebar

Related Questions

I have a scenario where I have to update multiple rows in a table
I have a table named Books which contains 3 columns. TableName: Books Columns: BookId
I have this scenario: A table named table 1 , with a column named
Heres my scenario. I have a table with 3 rows I want to return
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
The architecture for this scenario is as follows: I have a table of items
I have a scenario outline table that looks like the following: Scenario Outline: Verify
I have the scenario where the data from a single table must be in
i have a scenario, i want to monitor database(SQL Server) table, if record is
I have the following scenario: a table of projects and a table of persons,

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.