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

  • Home
  • SEARCH
  • 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 6547729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:51:59+00:00 2026-05-25T11:51:59+00:00

Having an odd problem with a MySQL query, I can’t really figure out how

  • 0

Having an odd problem with a MySQL query, I can’t really figure out how to get the data organized as I wish.

I’m building search-script in PHP, but the database structure isn’t in the way that I would like.

Okay, say that I have three tables (these are completely made up):

EMPLOYES
id      name        city        hired
-------------------------------------------------
1       Jim         0810        2001
2       Stan        6777        2002
3       George      6532        2009

SALARY
id      amount      year
--------------------------------
1       2000        2009
1       2500        2010
1       2800        2011
2       2100        2009
2       2200        2010
2       2500        2011
3       2200        2009
3       2300        2010
3       2800        2011

CONTACT
city    areacode    cityname
-----------------------------
0810    0300        Tampa
6777    0800        Miami
6532    0210        Atlanta 

Now, if I stick to LEFT JOINs etc. I am able to get a result that look like this, where it repeats every row in in the Salary table:

name    cityname    hired   salary
----------------------------------
Jim     Tampa       2001    2000
Jim     Tampa       2001    2500
Jim     Tampa       2001    2800
...

But what I really want is something like this:

name    cityname    hired   2009    2010    2011
------------------------------------------------
Jim     Tampa       2001    2000    2500    2800
...

Any way that I can achieve this with SQL?

  • 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-25T11:51:59+00:00Added an answer on May 25, 2026 at 11:51 am
    SELECT EMPLOYES.*, GROUP_CONCAT(salery) 
    FROM EMPLOYES JOIN SALERY USING(id) 
    GROUP BY id
    

    http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

    But you better do it by hand, not in SQL. When I say “by hand” I mean by writing a program that does that for you. We are all programmers here, aren’t we?

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

Sidebar

Related Questions

I am having a really odd problem with Flash CS4. I have a MovieClip
Can anyone help with an odd Ruby Gem problem I'm having - note I've
Currently having this really odd problem with my layout IE7. I'm not very experienced
I'm having an odd problem with the following query, it works all correct, the
I'm having a very odd problem that I can't seem to track down. Any
I am having a really odd problem trying to set a simple float value
I am having a very odd problem with local variables being out of context
We're having a really odd problem. Basically the Facebook Connect button we put up
I am having an odd problem with my SQL Server express 2005 DB. It
I'm having a rough time with this membership stuff. OK, so, it's really odd.

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.