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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:06:59+00:00 2026-06-11T20:06:59+00:00

I have a syntax issue with my use of GROUP_CONTACT. With a sql statement

  • 0

I have a syntax issue with my use of GROUP_CONTACT.

With a sql statement that looks like this:

SELECT 

     s.school_code
    , s.school_name
    ,st.subject
    ,sg.subgroup
    ,GROUP_CONCAT(IF(r.year=2012,a.proficiency_index,NULL)) AS pi_2012
    ,GROUP_CONCAT(IF(r.year=2013,a.proficiency_index,NULL)) AS pi_2013

FROM 
    ayp_data a
        INNER JOIN 
            report_year r ON
                a.report_year_id = r.id
        INNER JOIN
            school s ON
                a.school_code_id = s.id
        INNER JOIN
            sub_group sg ON
                a.subgroup_id = sg.id
        INNER JOIN
            `subject` st ON
                a.subject_id = st.id

GROUP BY
      report_year_id,
      s.school_code
    , s.school_name
    ,st.subject
    ,sg.subgroup
HAVING 
s.school_name = 'Moody Elementary School' AND 
`subject` = 'Mathematics' AND 
`subgroup` = 'All Students'

I am getting results like this:

SCHOOL_CODE     SCHOOL_NAME     SUBJECT     SUBGROUP    PI_2012     PI_2013
0065    Moody Elementary School     Mathematics     All Students    9.640000343322754   (null)
0065    Moody Elementary School     Mathematics     All Students    (null)  10.920000076293945

I want to merge the two rows into one and put non-null field values PI_2012 and PI_2013 on the same line.

I thought I could do that with GROUP_CONTACT; but it’s not doing as I thought it would.

How could I use GROUP_CONCAT to merge these fields?

Or, is there an even smarter way to do this?

I have the full schema and query here on SQL Fiddle.

  • 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-11T20:07:01+00:00Added an answer on June 11, 2026 at 8:07 pm

    If you don’t want separate years to appear in separate rows, then you need to remove report_year_id from the GROUP BY clause. That is — you need to change this:

    GROUP BY
          report_year_id,
          s.school_code
        , s.school_name
        ,st.subject
        ,sg.subgroup
    

    to this:

    GROUP BY
          s.school_code
        , s.school_name
        ,st.subject
        ,sg.subgroup
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I most likely have a syntax issue (SQL command and error copied below) -
I have a syntax error that I don't know how to fix. This is
I have this simple Select box that is suppose to store the selected value
I am trying to make use of this Syntax highlighter. I have tried to
You have an error in your SQL syntax; check the manual that corresponds to
I have a simple issue with Entity Framework syntax for the not in SQL
I have a couple of views which use the SELECT CASE syntax.However when I
I want to build an notepad-style application on android that will have syntax highlighting.
I would like to have the following syntax: python utility.py file1 FILE1 file2 FILE2
I'm sure I have seen this syntax <%= Url.Action((MyController c) => c.MyMethod(a)) %> or

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.