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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:18:21+00:00 2026-06-03T19:18:21+00:00

I am having issues with a sql query. I have following table (I simplified

  • 0

I am having issues with a sql query.

I have following table (I simplified it a bit):

 ChainId    ComponentId    TransmitEndpointId
   1            156               NULL
   1            156               7
   1            157               7
   2            510               6
   2            510               6
   2            511               6
   2            511               8

What I need to do is get the number of TransmitEndpointId’s foreach ‘unique’ ComponentId in a ‘unique’ ChainId.
So the result of the above data would be: 5 (2 unique componentId’s in Chain 1 & 2 unique componentId’s in Chain 2 with 2 different TransmitId’s ==> NULL values don’t count)

This is quite complex and have no idea on how to start with this query.

Can anybody help?

Thanks in advance.

  • 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-03T19:18:22+00:00Added an answer on June 3, 2026 at 7:18 pm

    add the where TransmitEndpointId is not null or you will get a 0 because of the NULL

    SELECT ChainId,
           ComponentId,
           count(distinct TransmitEndpointId)
    FROM chain
    where TransmitEndpointId is not null
    GROUP BY ChainId, ComponentId
    
    select sum(endPointNr) from 
    (
    SELECT count(distinct TransmitEndpointId) as     endPointNr
    FROM chain
    where TransmitEndpointId is not null
    GROUP BY ChainId, ComponentId
    ) X
    

    enter image description here

    EDIT (why add TransmitEndpointId is not null)

    enter image description here

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

Sidebar

Related Questions

I'm learning SQL and I'm having trouble with a query. I have the following
I am having trouble with the following SQL statement. I have had this issue
I'm looking to perform a somewhat complex SQL Query and I'm having a bit
Am having some SQL ( SqlCe ) issues I was getting the following error:
I have a table in SQL Server 2008 with a column having the string
I'm having a bit of issue converting the following t-sql statement to Linq (using
I have the following SQL Server 2008 query that works for all of my
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I am having serious performance issues with a spatial update query in SQL Server
I'm having an issue extracting a substring in SQL query results. Here's the situation:

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.