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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:55:34+00:00 2026-05-27T11:55:34+00:00

I have a small problem with an SQL statement with a GROUP_CONCAT. I have

  • 0

I have a small problem with an SQL statement with a GROUP_CONCAT.

I have this statement:

SELECT ni.*, GROUP_CONCAT(newsletter_item_receivers.value) AS receivers, nf.*, GROUP_CONCAT(nm.mailgroup_name) AS mailgroups
FROM newsletter_items ni
INNER JOIN newsletter_fields nf ON (nf.field_letter_uid = ni.letter_id)                                                          
LEFT JOIN newsletter_item_receivers ON (newsletter_item_receivers.letter_id = ni.letter_id)
INNER JOIN newsletter_mailgroups nm ON (FIND_IN_SET(nm.mailgroup_id, newsletter_item_receivers.value))
WHERE nf.field_name = 'letter_headline' AND ni.template = '". $template ."' 
GROUP BY ni.letter_id

I have done something wrong, because my output is messed up.

I have 4 tables:

newsletter_items that have these columns:

letter_id (int)
letter_date (int)
template (varchar)
status (int)

and newsletter_item_receivers
that have these columns:

rid (int)
letter_id (int)
value (int)

newsletter_mailgroups

mailgroup_id (int)
mailgroup_name (varchar)

newsletter_fields

field_uid (int)
field_name (varchar)
field_content (text)
field_letter_uid (int)

I get almost the output that I want, but my mailgroups are displayed wrong. I want it to be displayed like

Group A, Group C but it is displayed like

Group A, Group C, Group A, Group C, Group C
when my newsletter_item_receivers tables contains this:

rid | letter_id | value
1   | 1         | 2
2   | 1         | 3
3   | 2         | 1

newsletter_item_receivers.letter_id refers to newsletter_items.letter_id and
newsletter_item_receivers.value refers to newsletter_mailgroups.mailgroup_id

Is there someone who can see what I have done wrong?

  • 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-27T11:55:34+00:00Added an answer on May 27, 2026 at 11:55 am

    Try this :-

    group_concat( DISTINCT newsletter_item_receivers.value 
                  ORDER BY newsletter_item_receivers.value)
    

    And

    group_concat( DISTINCT nm.mailgroup_name 
                  ORDER BY nm.mailgroup_name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem. I'm populating a select tag with results from a
SQL to find duplicate entries (within a group) I have a small problem and
I have a small problem that I think should be easily handled by SQL
I have this small code using SQL Server Agent to Run a Remote Package
I'm doing a small calculation in the select statement of an sql query along
I have a small problem with an SQL query. Maybe I just couldn't wake
This small SQL error is bugging me. It doesn't seem to be a problem
have small problem, and would very much appreciate help :) I should convert byte
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small problem with interfaces. Here it is in Pseudo code :

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.