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 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

Ask A Question

Stats

  • Questions 174k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: map.setZoom(6); var point = new GLatLng(26.228595038041917, 50.54535984992981); map.setCenter(point); May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer Since you stated that your input is guaranteed to be… May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer Please change your call to $.each as follows: $.each( cart.items,… May 12, 2026 at 2:54 pm

Related Questions

I'm a little confused over a ManualResetEvent that I'm using which doesn't appear to
I'm having problems with some code to create a CDialog based window. The code
Im pretty new to CI so bear with me here. I have just setup
Maybe I should first give an idea of what I want to accomplish as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.