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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:55:12+00:00 2026-05-20T12:55:12+00:00

Conceptually, I am trying to grab 8 separate survey scores for every user in

  • 0

Conceptually, I am trying to grab 8 separate survey scores for every user in my system. I want to output all 8 scores connected to a given user outputted on the same row. Here is my best shot to achieve this:

SELECT cp.CONSUMER_ID,
       bsr1.SCORE AS SET_1_SCORE,
       bsr2.SCORE AS SET_2_SCORE,
       bsr3.SCORE AS SET_3_SCORE,
       bsr4.SCORE AS SET_4_SCORE,
       bsr5.SCORE AS SET_5_SCORE,
       bsr6.SCORE AS SET_6_SCORE,
       bsr7.SCORE AS SET_7_SCORE,
       bsr8.SCORE AS SET_8_SCORE
FROM 
CONSUMER_PROFILE AS cp
LEFT JOIN survey_scores AS bsr1
ON bsr1.SET_ORDER=1 
AND bsr1.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr2
ON bsr2.SET_ORDER=2
AND bsr2.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr3
ON bsr3.SET_ORDER=3
AND bsr3.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr4
ON bsr4.SET_ORDER=4
AND bsr4.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr5
ON bsr5.SET_ORDER=5
AND bsr5.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr6
ON bsr6.SET_ORDER=6
AND bsr6.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr7
ON bsr7.SET_ORDER=7
AND bsr7.CUSTOMER_ID=cp.CONSUMER_ID
LEFT JOIN survey_scores AS bsr8
ON bsr8.SET_ORDER=8
AND bsr8.CUSTOMER_ID=cp.CONSUMER_ID

This returns the proper output, but however is terribly slow. How would you suggest I optimize it?

  • 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-20T12:55:13+00:00Added an answer on May 20, 2026 at 12:55 pm

    The first thing you need is an index on survey_scores(SET_ORDER, consumer_id, score) or at least survey_scores(SET_ORDER, consumer_id). It will then work quite well even with your query.

    An alternative way to write it would be

    SELECT cp.CONSUMER_ID,
           MAX(CASE WHEN bsr1.SET_ORDER=1 THEN bsr1.SCORE END) AS SET_1_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=2 THEN bsr1.SCORE END) AS SET_2_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=3 THEN bsr1.SCORE END) AS SET_3_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=4 THEN bsr1.SCORE END) AS SET_4_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=5 THEN bsr1.SCORE END) AS SET_5_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=6 THEN bsr1.SCORE END) AS SET_6_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=7 THEN bsr1.SCORE END) AS SET_7_SCORE,
           MAX(CASE WHEN bsr1.SET_ORDER=8 THEN bsr1.SCORE END) AS SET_8_SCORE
    FROM CONSUMER_PROFILE AS cp
    LEFT JOIN survey_scores AS bsr1
    ON bsr1.SET_ORDER in (1,2,3,4,5,6,7,8)
    AND bsr1.CUSTOMER_ID=cp.CONSUMER_ID
    GROUP BY cp.CONSUMER_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Conceptually speaking how would one go about writing an achievement system for a website
I have a number of classes that are all related conceptually, but some more-so
I have several somewhat separate programs, that conceptually can fit into a single project.
I'm looking at modifying a toy OS system and I'm just trying to learn
I am trying to understand conceptually the best way to deliver real streaming audio
I'm trying to do something that is conceptually similar to this, but can't seem
I'm trying to come up with a scoring system for some behavioural psychology research.
I'm trying to get a handle on OpenGL VAOs/VBOs, and conceptually I'm there, but
I'm trying to understand conceptually how to use Amazon EC2 to speed up the
I'm trying to use Interop.MSProject with C# to do something that conceptually, should be

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.