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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:07:53+00:00 2026-05-20T01:07:53+00:00

This is a continuation of the SQL joining dilemma I had yesterday… I have

  • 0

This is a continuation of the SQL joining dilemma I had yesterday…

I have the following tables:

(Student)

|   ID    |  NAME   |
|  1234   |  dave   |

(Assessment)

|     ID     |    DATE    | STUDENT_ID |  TYPE  |
|     1      |  02/03/11  |    1234    | School |
|     2      |  05/03/11  |    1234    | Parent |

(Concern) 

|   ID   |  ASSESSMENT_ID  | TOPIC | LEVEL | TOPIC_NUMBER |
|    1   |         1       | apple |   3   |       1      |
|    2   |         1       | pears |   2   |       2      |
|    3   |         2       | mango |   2   |       1      |
|    4   |         2       | dates |   4   |       2      |

I want to create a single row which combines the assessments and concerns:

| StudentId | TIoC1 | TIoC2 | TIoCScore1 | TIoCScore2 | PIoC1 | PIoC2 | PIoCScore1 | PIoCScore2 |
|   1234    | apple | pears |      3     |      2     | mango | dates |      2     |       4    |

This is to be exported to a stats package, so the structure has to remain as is.

This is the SQL I have now:

SELECT a_assessment.StudentId, 
TIoC1,TIoC2,TIoCScore1,TIoCScore2,PIoC1,PIoC2,PIoCScore1,PIoCScore2
FROM
  dbo.Assessment a_assessment
  LEFT OUTER JOIN
  (
    SELECT P.StudentId, C1.Topic AS TIoC1, C2.Topic AS TIoC2, C3.Topic AS TIoC3, C4.Topic AS TIoC4,
      C1.Level AS TIoCScore1, C2.Level AS TIoCScore2, C3.Level AS TIoCScore3, C4.Level AS TIoCScore4
    FROM dbo.Assessment P
      LEFT JOIN Concern C1 ON P.Id = C1.Assessment_Id and C1.TopicNumber = 1
      LEFT JOIN Concern C2 ON P.Id = C2.Assessment_Id and C2.TopicNumber = 2
    WHERE P.Type = 'School'
  ) a_school_cons
  ON a_school_cons.StudentId = a_assessment.StudentId
  LEFT OUTER JOIN
  (
    SELECT P.StudentId, C1.Topic AS PIoC1, C2.Topic AS PIoC2
      C1.Level AS PIoCScore1, C2.Level AS PIoCScore2
    FROM dbo.Assessment P
      LEFT JOIN Concern C1 ON P.Id = C1.Assessment_Id and C1.TopicNumber = 1
      LEFT JOIN Concern C2 ON P.Id = C2.Assessment_Id and C2.TopicNumber = 2
    WHERE P.Type = 'Parent'
  ) a_parent_cons
ON a_parent_cons.StudentId = a_assessment.StudentId

The problem is, it returns two identical rows!

| StudentId | TIoC1 | TIoC2 | TIoCScore1 | TIoCScore2 | PIoC1 | PIoC2 | PIoCScore1 | PIoCScore2 |
|   1234    | apple | pears |      3     |      2     | mango | dates |      2     |       4    |
|   1234    | apple | pears |      3     |      2     | mango | dates |      2     |       4    |

And I can’t work out how to update this to only return one – any help gratefully received!!

Thanks as always!

  • 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-20T01:07:54+00:00Added an answer on May 20, 2026 at 1:07 am

    Doesn’t adding a simple DISTINCT work here?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation of a couple of previous questions I've had. I have
This is a continuation of this question from yesterday . Here are my three
This is a continuation of Why do we have to set __block variable to
This is a continuation of the question here: JBoss - does app have to
Occasionally, I have had to build a SQL string in VBA and execute it
This post is an continuation of this post I have DlUser Class each object
A continuation from this question I need a SQL statement that returns the number
This is a continuation of the question Java rounded Swing JButton . I have
This question is in continuation of this post , I have tried installing Xerces-C
This question is a continuation of this question: ( Oracle APEX - SQL -

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.