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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:36:41+00:00 2026-05-12T08:36:41+00:00

UPDATE Finally managed to work it out! Thanks for all the help from everyone.

  • 0

UPDATE

Finally managed to work it out! Thanks for all the help from everyone. If you spot any potential errors or scope for improvement in my query please let me know.

SELECT * 
FROM TBL_CAMPAIGNS C
INNER JOIN TBL_MEMBERS M
    ON C.campaign_MemberId = M.members_Id
INNER JOIN TBL_CAMPAIGNS_CHARITIES CC
    ON C.campaign_Key = CC.camchar_CampaignID
INNER JOIN TBL_CHARITIES CH
    ON CC.camchar_CharityID = CH.cha_Key
LEFT OUTER JOIN (
    select recip_Chosen, count(recip_CampaignId) as ChosenCount
    from TBL_CAMPAIGNRECIPIENTS
    WHERE recip_CampaignId =  @campaign
    group by recip_Chosen
) CRC
on CH.cha_Key = CRC.recip_Chosen
WHERE C.campaign_Key = @campaign

Thanks!!!

///////////////////

After some really useful advice i decided to implement orbMan’ suggestion as follows;

SELECT * 
FROM TBL_CAMPAIGNS C
INNER JOIN TBL_MEMBERS M
    ON C.campaign_MemberId = M.members_Id
INNER JOIN TBL_CAMPAIGNS_CHARITIES CC
    ON C.campaign_Key = CC.camchar_CampaignID
INNER JOIN TBL_CHARITIES CH
    ON CC.camchar_CharityID = CH.cha_Key
WHERE C.campaign_Key = @campaign

This returns 1 row for each charity associated with a given campaign (as associated via TBL_Campaigns_Charities). However, i also have another table(TBL_CAMPAIGNRECIPIENTS CR) which details each person invited to take part in the campaign. On visiting the campaign page they can select one of the charities linked to the campaign.

Now i need to know how many people have chosen each of the associated charities(CR.recip_Chosen). Their details arent important. I just need to know how many people have selected each of the associated charities.

So something like;

COUNT CH.cha_Key, FROM CR WHERE CR.recip_Chosen = CH.cha_Key

but integrated into the statement above.

Thanks in advance.

ORIGINAL POST BELOW:

/ / / / / / / / / / / / / / / / / / /

Hi,

I need to gain data from across 3 tables. The first two are straight forward and are currently grabbed as;

 SELECT * FROM TBL_CAMPAIGNS C
 JOIN TBL_MEMBERS M
 ON C.campaign_MemberId = M.members_Id
 WHERE C.campaign_Key = @campaign

The table ‘TBL_CAMPAIGNS’ contains various columns, five of which hold an int. This int refers to the key of the 3rd table ‘TBL_CHARITIES’. How do i return the data of the third table in combination with the above?

Ive created the following so far;

 SELECT * FROM TBL_CAMPAIGNS C
 JOIN TBL_MEMBERS M
 ON C.campaign_MemberId = M.members_Id
 JOIN TBL_CHARITIES CH
 ON CH.cha_Key = C.campaign_Char1
 WHERE C.campaign_Key = @campaign

But, as you can tell, that only returns C.campaign_Char1. What about C.campaign_Char2, C.campaign_Char3, C.campaign_Char4, C.campaign_Char5 ?????

I did try this;

 SELECT * FROM TBL_CAMPAIGNS C
 JOIN TBL_MEMBERS M
 ON C.campaign_MemberId = M.members_Id
 JOIN TBL_CHARITIES CH
 ON CH.cha_Key = C.campaign_Char1
 AND CH.cha_Key = C.campaign_Char2
 AND CH.cha_Key = C.campaign_Char3
 .......
 WHERE C.campaign_Key = @campaign

But, of course this doesnt work!

Any suggestions / 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-05-12T08:36:42+00:00Added an answer on May 12, 2026 at 8:36 am

    This is a denormalized design and that is why you are having difficulty querying it. It would be easier if (instead of columns campaign_Char1 through 5) you had a many-to-many table between TBL_CAMPAIGNS and TBL_CHARITIES. E.g., TBL_CAMPAIGNS_CHARITIES. This would contain a Campaign ID and a CharityID.

    Then your query would be:

    SELECT * 
    FROM TBL_CAMPAIGNS C
    INNER JOIN TBL_MEMBERS M
        ON C.campaign_MemberId = M.members_Id
    INNER JOIN TBL_CAMPAIGNS_CHARITIES CC
        ON C.campaign_Key = CC.CampaignID
    INNER JOIN TBL_CHARITIES CH
        ON CC.CharityID = CH.cha_Key
    WHERE C.campaign_Key = @campaign
    

    Update:

    SELECT * 
    FROM TBL_CAMPAIGNS C
    INNER JOIN TBL_MEMBERS M
        ON C.campaign_MemberId = M.members_Id
    INNER JOIN TBL_CAMPAIGNS_CHARITIES CC
        ON C.campaign_Key = CC.camchar_CampaignID
    INNER JOIN TBL_CHARITIES CH
        ON CC.camchar_CharityID = CH.cha_Key
    LEFT OUTER JOIN (
        select recip_Chosen, count(*) as ChosenCount
        from TBL_CAMPAIGNRECIPIENTS 
        group by recip_Chosen
    ) CRC
    on CH.cha_Key = CRC.recip_Chosen
    WHERE C.campaign_Key = @campaign
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed finally to get Solr working, with the help of all you
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find
I've started working with ASP.net AJAX (finally ☺). and I've got an update panel
Update: I reported this as a bug to Apple and they fixed it! All
Update : This is no longer an issue from C# 6, which has introduced
I have managed to develop an extension for visual studio Update web reference action
Right, after much struggle I finally managed to get a sort of shared folder
Good morning, I finally managed to store the Facebook usernames in my database after
After many hours of debugging and analysis, I have finally managed to isolate the
Update and Solution I finally got everything working after 1. Uninstalling everything ruby-related in

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.