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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:11:07+00:00 2026-05-29T10:11:07+00:00

I should note that id is not unique in the tdemog_pfp table – there

  • 0

I should note that id is not unique in the tdemog_pfp table – there is a unique field there that auto-increments – could this be an issue?

Ok, I have the following SQL query:

SELECT id, name, total_staff AS StaffCount, COUNT( q60a ) AS TotalResp, (COUNT( q60a ) / total_staff * 100) AS Perc 
FROM tdemog_pfp
LEFT JOIN tresults_pfp ON tdemog_pfp.id = tresults_pfp.q60a
GROUP BY name
ORDER BY name

Now, the demog table has multiple rows where entries can have q59, q60a, q60b and so on for the colomn qnum

I want to bring back the results WHERE qnum = q60a but I have a problem, when I add it to the above to make the following – it brings back zero results (an empty result set), which is incorrect:

SELECT id, name, total_staff AS StaffCount, COUNT( q60a ) AS TotalResp, (COUNT( q60a ) / total_staff * 100) AS Perc 
FROM tdemog_pfp
LEFT JOIN tresults_pfp ON tdemog_pfp.id = tresults_pfp.q60a
    WHERE qnum = q60a
GROUP BY name
ORDER BY name

Where am I going wrong?

Thanks,

H.

  • 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-29T10:11:08+00:00Added an answer on May 29, 2026 at 10:11 am

    Make your test part of the JOIN condition instead of testing in the WHERE clause.

    SELECT id, name, total_staff AS StaffCount, COUNT( q60a ) AS TotalResp, (COUNT( q60a ) / total_staff * 100) AS Perc 
    FROM tdemog_pfp
    LEFT JOIN tresults_pfp ON tdemog_pfp.id = tresults_pfp.q60a
        AND qnum = q60a
    GROUP BY name
    ORDER BY name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read everywhere (and see in practice) that usernames should not be changeable. When
Note that I'm not actually doing anything with a database here, so ORM tools
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
Should I still be using tables anyway? The table code I'd be replacing is:
Should libraries that the application relies on be stored in source control? One part
My schema looks something like this: CREATE TABLE plans ( id SERIAL PRIMARY KEY,
Let's say I have a list that looks like this: <ul> <li id=q></li> <li
I am creating a table during runtime. This is how I do it: AdoCommand1.Connection:=AdoConnection1;
I am working on Oracle. I have this large property-indexer table ( THE_TABLE ),
I have a large and unique integer (actually a SHA1 hash). Note: While I'm

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.