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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:35:41+00:00 2026-05-14T06:35:41+00:00

Hi I’m having trouble with my query combining records when it shouldn’t. I have

  • 0

Hi I’m having trouble with my query combining records when it shouldn’t.

I have two tables Authors and Publications, they are related by Publication ID in a many to many relationship. As each author can have many publications and each publication has many Authors. I want my query to return every publication for a set of authors and include the ID of each of the other authors that have contributed to the publication grouped into one field. (I am working with mySQL)

I have tried to picture it graphically below

    Table: authors               Table:publications
AuthorID | PublicationID        PublicationID | PublicationName
    1    |   123                       123    |       A
    1    |   456                       456    |       B
    2    |   123                       789    |       C
    2    |   789
    3    |   123
    3    |   456

I want my result set to be the following

 AuthorID | PublicationID | PublicationName | AllAuthors
     1    |       123     |        A        |    1,2,3
     1    |       456     |        B        |    1,3
     2    |       123     |        A        |    1,2,3
     2    |       789     |        C        |     2
     3    |       123     |        A        |    1,2,3
     3    |       456     |        B        |    1,3

This is my query

Select   Author1.AuthorID,
    Publications.PublicationID,
    Publications.PubName,
    GROUP_CONCAT(TRIM(Author2.AuthorID)ORDER BY Author2.AuthorID ASC)AS 'AuthorsAll'
FROM Authors AS Author1
LEFT JOIN Authors AS Author2
ON Author1.PublicationID = Author2.PublicationID
INNER JOIN Publications
ON Author1.PublicationID = Publications.PublicationID
WHERE Author1.AuthorID ="1" OR Author1.AuthorID ="2" OR Author1.AuthorID ="3" 
GROUP BY Author2.PublicationID

But it returns the following instead

 AuthorID | PublicationID | PublicationName | AllAuthors
     1    |       123     |        A        |    1,1,1,2,2,2,3,3,3
     1    |       456     |        B        |    1,1,3,3
     2    |       789     |        C        |     2

It does deliver the desired output when there is only one AuhorID in the where statement.
I have not been able to figure it out, does anyone know where i’m going 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-14T06:35:41+00:00Added an answer on May 14, 2026 at 6:35 am

    To eliminate duplicate authors, change:

    ON Author1.PublicationID = Author2.PublicationID
    

    to:

    ON Author1.PublicationID = Author2.PublicationID AND
       Author1.AuthorID <> Author2.AuthorID
    

    Also, change:

    GROUP BY Author2.PublicationID
    

    to:

    GROUP BY Author1.AuthorID, Author2.PublicationID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.