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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:51:58+00:00 2026-06-03T09:51:58+00:00

I need some help getting data from several tables. This is the tables I

  • 0

I need some help getting data from several tables.

This is the tables I have:

_______________   ______________   ___________  _______________  _____________
|_tblUsers____|   |_tblAnswers__|  |_tblAlt__|  |_tblQuestion_|  |_survey_____|
| userID      |   | answerAltID |  | altID   |  | questID     |  | surveyID   |
| username    |   | userID      |  | altText |  | questText   |  | surveyName |
|_____________|   |_____________|  |_questID_|  |_surveyID____|  |____________|

TblUsers have a list of users in the system, tblAnswers have all answers that has been given from users, tlbAlt holds alternatives for a question, and tblQuestion has the questions. There is one more table called tblSurveys, but that’s not needed here as the ID is mentioned in the tblQuestion.

This is what I have so far:

SELECT
tblQuestion.questText,
tblAlt.altText,
Count(tblAnswers.answerID) as answers_count,
(SELECT COUNT(answerID) FROM tblAnswers, tblAlt 
WHERE tblAnswers.answerAltID = tblAlt.altID 
AND tblAlt.questID = " & CInt(questionID) & ") as total_count
FROM tblAlt, tblQuestion
LEFT JOIN tblAnswers ON (tblAlt.altId = tblAnswers.altID)
WHERE tblAlt.questID = " & CInt(questionID) & "
GROUP BY tblAlt.altText;

This returns rows like this:

| What is blablabla? | The answer is… | 2 (has answered) | 10 (total
answers) |

This unfortunately only returns all rows for one question. Is there a way to get all rows that is a part of same survey (based on surveyID)?

If want the output to be like this:

| What is blablabla? | The answer is… | 2 (has answered) | 10 (total
answers) | Name of Survey |

I want to return ALL alternatives (with how many answered, total answers, related question and survey).


Update:

This my input:

SELECT tblalternativ.altTekst, tblalternativ.altID, Count(tblsvar.svarAltID) as antSvar, 
(SELECT COUNT(*) FROM tblsvar, tblalternativ 
WHERE tblsvar.svarAltID = tblalternativ.altID 
AND tblalternativ.altSpmID = " & CInt(lblQuestion.Tag) & ") as antTotal, 
(SELECT Count(*) FROM tblalternativ WHERE altSpmID = " & CInt(lblQuestion.Tag) & ") as spmTotal 
FROM(tblalternativ) LEFT JOIN tblsvar ON (tblalternativ.altId = tblsvar.svarAltID) 
WHERE(tblalternativ.altSpmID = " & CInt(lblQuestion.Tag) & ")
GROUP BY tblalternativ.altTekst ORDER BY tblalternativ.altID ASC

My output:

altTekst    altID   antSvar antTotal    spmTotal
Black         83         1      3              5
Green         84         1      3              5
Yellow        85         1      3              5
White         86         0      3              5
Pink          87         0      3              5

But this only show statistics for one question. I want to show for all questions in one survey. So I need to get all altTekst for that survey, question name, and ID of survey.

I want:

spmTekst      altTekst  altID   antSvar antTotal    spmTotal   evalID
What is...    Black         83         1        3          5        1
What is...    Green         84         1        3          5        1
What is...    Yellow        85         1        3          5        1
What is...    White         86         0        3          5        1
What is...    Pink          87         0        3          5        1
Who is....    The king      88         2        3          3        1
Who is....    The pope      89         0        3          3        1
Who is....    The president 90         1        3          3        1
Which....     Shoe          91         2        3          2        1
Which....     Hat           92         1        3          2        1

In other words, I want the statistics from all questions in same survey (based on evalID).

  • 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-03T09:51:59+00:00Added an answer on June 3, 2026 at 9:51 am

    Try this(Not at all optimized, just added the survey part to it):

    SELECT    tblQuestion.questText, tblAlt.altText, 
              Count(tblAnswers.answerAltID) AS answers_count,
               (SELECT COUNT(answerAltID) FROM tblAnswers, tblAlt 
               WHERE  tblAnswers.answerAltID = tblAlt.altID AND 
                      tblAlt.questID = " & CInt(questionID) & ") as total_count,
              survey.surveyName
    FROM      survey, tblQuestion, tblAlt
    LEFT JOIN tblAnswers ON (tblAlt.altId = tblAnswers.answerAltID)
    WHERE     tblAlt.questID = " & CInt(questionID) & " AND 
              tblQuestion.surveyID = survey.surveyID
    GROUP BY  tblAlt.altText;
    

    Edit: Try this then:

    SELECT    tblQuestion.questText AS spmTekst, tblAlt.altText AS altTekst, 
              tblAlt.altID, 
              Count(tblAnswers.answerAltID) AS antSvar,
              COUNT(tblAlt.altID) AS antTotal,
              COUNT(tblQuestion.questID) AS spmTotal,
              survey.surveyID AS evalID
    FROM      tblQuestion 
    JOIN      survey ON (survey.surveyID = tblQuestion.surveyID)
    JOIN      tblAlt ON (tblAlt.questID = tblQuestion.questID)
    LEFT JOIN tblAnswers ON (tblAnswers.answerAltID = tblAlt.altID)
    WHERE     tblAlt.questID = " & CInt(questionID) & " AND -- what really is this? review this
              survey.surveyID = '123' -- the value u want
    GROUP BY  tblAlt.altText
    ORDER BY  tblAnswers.answerAltID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help to figure this out .. I am getting data from
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help with a query.. I have three tables. Source id name 1
I need some help with a binding error I'm getting from a style on
I have an issue getting data from three tables, which I want to return
I need some help in understanding what is happening here .I am getting a
I need some help. Here's what I'm getting right now: img ref I need
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help with this problem in implementing with XSLT, I had already implemented

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.