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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:52:15+00:00 2026-06-04T10:52:15+00:00

I don’t really know how to even search for resolution of this problem, didn’t

  • 0

I don’t really know how to even search for resolution of this problem, didn’t find anything specific, so here goes…

I have four tables, let’s simplify them:

  players
  =======
  id    name    surname
  1     John    Arbuckle
  2     Walter  White
  3     Don Draper
  4     Louis   CK
  5     Tyrion  Lannister
  6     Abed    Nadir

  sports
  ======
  id    sport
  1     football
  2     handball

  positions
  =========
  id    name    sport_id
  1     goalie  1
  2     defense 1
  3     attack  1
  4     goalie  2
  5     pivot   2
  6     wing    2
  7     center  2

  player_position
  ===============
  player_id position_id
  1         1
  1         2
  1         5
  2         7
  2         5
  3         2
  4         2
  5         1
  5         3
  6         7
  6         5

So, player can play multiple sports and on multiple positions. First, I have to display list of players for a certain sport, including a column with positions they play.

What I started with is JOIN statement where I’d join those tables and have multiple rows for each player ID. That’s close, but not very correct. And what I need to get is a tables like this:

FOOTBALL

    ID  name    surname     position
    1   John    Arbuckle    PHP array(goalie,defense)

HANDBALL

    ID  name    surname     position
    1   John    Arbuckle    PHP array(pivot)

EDIT:
So what I was looking for was GROUP_CONCAT().
Thanks guys!

  • 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-04T10:52:17+00:00Added an answer on June 4, 2026 at 10:52 am
    select p.id, p.name, p.surname, group_concat(po.name)
    from players p 
    inner join player_position pp on pp.player_id = p.id
    inner join positions po on po.id = pp.position_id
    inner join sports s on s.id = po.sport_id
    where s.sport = 'football'
    group by p.id
    

    See this SQLFiddle example

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

Sidebar

Related Questions

Don't know if this is an eclipse specific problem but whenever I declare a
Don't know if anyone can help me with this or if it's even possible.
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
I don't know to explain this but here i go, so i have a
don't know if the title describes anything about what I'm trying to say but
Don't really know how to formulate the title, but it should be pretty obvious
I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question

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.