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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:00:47+00:00 2026-06-03T14:00:47+00:00

So I have this: const string sqlString = SELECT * FROM Causes c INNER

  • 0

So I have this:

    const string sqlString =
        "SELECT * FROM Causes c INNER JOIN CauseMembers m ON " +
        "(c.Id = m.CauseId) AND (UserName = @UserName) " +
        "ORDER BY c.DateTime DESC;";

Works fine, however I’d like to return a generated column containing the number of rows returned from this query from the table causemembers. So that I can get the actual members who joined this ’cause’ (from Causes).

Your inputs? 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-06-03T14:00:48+00:00Added an answer on June 3, 2026 at 2:00 pm

    If you’re using SQL Server 2005 or higher, then you can use a window function:

    SELECT <ALL COLUMNS YOU'RE INTERESTED IN>, COUNT(m.CauseId) OVER (PARTITION BY c.ID)
    FROM Causes c JOIN CauseMembers m ON (c.Id = m.CauseId) AND (UserName = @UserName)
    ORDER BY c.DateTime DESC
    

    This will get you a count of the number of rows returned per cause ID. If you want to ensure that every cause is returned, whether any members belong to it or not, then change the JOIN to a LEFT OUTER JOIN. If there are no CauseMembers, then the NULL from the outer join will not be counted, so you’ll get zero.

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

Sidebar

Related Questions

I have this public List<TableA> GetRecords(List<string> keys) { const string query = FROM TableA
I have the following string: const char *str = \This is just some random
I have some code that looks like: static const std::string and( AND ); This
I have a string as const char *str = Hello, this is an example
I have a class whose constructor takes a const reference to a string. This
I have this for ex: Link This code: const String nick = Alex; const
I have a function like this const string &SomeClass::Foo(int Value) { if (Value <
In my header file, I have this: std::string StringExtend(const std::string Source, const unsigned int
I have this function declaration and its defination: declaration void laodFromFile( string const& fileName,
I have this: public static class Domain { private const string sessionKey = NHib.SessionKey;

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.