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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:20:04+00:00 2026-05-13T23:20:04+00:00

This one seems to be a simple problem, but I can’t make it work

  • 0

This one seems to be a simple problem, but I can’t make it work in a single
select or nested select
. Retrieve the authors and (if any) advisers of a
paper (article) into one row.

I order to explain the problem, here are the two data tables (pseudo)

papers (id, title, c_year)
persons (id, firstname, lastname)

plus a link table w/one extra attribute (pseudo):

paper_person_roles(
  paper_id
  person_id
  act_role ENUM ('AUTHOR', 'ADVISER')
)

This is basically a list of written papers (table: papers) and a list
of staff and/or students (table: persons)

An article my have (1,N) authors.
An article may have (0,N) advisers.
A person can be in ‘AUTHOR’ or ‘ADVISER’ role (but not at the same time).

The application eventually puts out table rows containing the following
entries:

TH: || Paper_ID  |  Author(s)          |   Title                 |   Adviser(s)  |
TD: ||   21334   |John Doe, Jeff Tucker|Why the moon looks yellow|Brown, Rayleigh|
...

My first approach was like:
select/extract a full list of articles into the application, eg.

SELECT 
   q.id, q.title
FROM 
   papers AS q
ORDER BY 
   q.c_year

and save the results of the query into an array (in the application). After this
step, loop over the array of the returned information and retrieve authors and
advisers (if any), via prepared statement (? is the paper’s id) from the link table
like:

APPLICATION_LOOP(paper_ids in array)
  SELECT 
      p.lastname, p.firstname, r.act_role 
  FROM 
      persons AS p, paper_person_roles AS r
   WHERE 
      p.id=r.person_id AND r.paper_id = ?
   # The application does further processing from here (pseudo):
   foreach record from resulting records
     if  record.act_role eq 'AUTHOR' then join to author_column
     if  record.act_role eq 'ADVISER' then join to avdiser_column
   end
   print id, author_column, title, adviser_column
APPLICATION_LOOP

This works so far and gives the desired output. Would it make
sense to put the computation back into the DB?

I’m not very proficient in nontrivial SQL and can’t find a
solution with a single (combined or nested) select call. I
tried sth. like

SELECT
    q.title 
    (CONCAT_WS(' ',
     (SELECT p.firstname, p.lastname AS aunames
      FROM persons AS p, paper_person_roles AS r
      WHERE q.id=r.paper_id AND r.act_role='AUTHOR')
     )
    ) AS aulist
FROM 
    papers AS q, persons AS p, paper_person_roles AS r

in several variations, but no luck …

Maybe there is some chance?

Thanks in advance

r.b.

  • 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-13T23:20:04+00:00Added an answer on May 13, 2026 at 11:20 pm

    The following query worked with my test-data, please give it a try.

    The two sub-queries are necessary to get the list of authors/advisers per paper.

    Select
      p.id,
      p.title,
      p_aut.aut_name,
      p_adv.adv_name
    From papers p
    Left Join (
      Select pp_aut.paper_id,
             Group_Concat(Concat(p_aut.firstname, ' ', p_aut.lastname)) aut_name
      From paper_person_roles pp_aut
      Join persons p_aut On (p_aut.id = pp_aut.person_id)
      Where pp_aut.act_role='AUTHOR'
      Group By pp_aut.paper_id
    ) p_aut On ( p_aut.paper_id = p.id )
    Left Join (
      Select pp_adv.paper_id,
             Group_Concat(Concat(p_adv.firstname, ' ', p_adv.lastname)) adv_name
      From paper_person_roles pp_adv
      Join persons p_adv On (p_adv.id = pp_adv.person_id)
      Where pp_adv.act_role='ADVISER'
      Group By pp_adv.paper_id
    ) p_adv On ( p_adv.paper_id = p.id )
    Group By p.id, p.title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 348k
  • Answers 348k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To only return one LI, I think you are gonna… May 14, 2026 at 6:29 am
  • Editorial Team
    Editorial Team added an answer From what you've described here, I'd say your solution does… May 14, 2026 at 6:29 am
  • Editorial Team
    Editorial Team added an answer You should run below code in the controller: <?php $this->load->library('table');… May 14, 2026 at 6:29 am

Related Questions

Okay, Now admittedly this sounds like a silly question; But, I actually have a
I have a minor problem where my (new) computer tends to completely freeze up.
Sorry for the long winded title, but the requirement/problem is rather specific. With reference
What are some ways that I can query the local machine's specifications (a range
Update: This only seems to be a problem at some computers. The normal, intuitive

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.