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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:02:16+00:00 2026-05-18T03:02:16+00:00

Does anyone know if it is possible to write a query that can produce

  • 0

Does anyone know if it is possible to write a query that can produce the following output based on the below tables?

I have managed to create the below results by creating three separate queries and passing the previous queries’ result set into the next query. But I was hoping for a more efficient way.

I want this output using ONE SQL if possible?

          baseball  computer  laptop
Jane Doe  5                  
Joe Blogs           8         8

These are the tables I have to work with:

persons table

id    first_name  last_name
101   Jane        Doe
576   Joe         Blogs

hobbies table

id hobby_type   hours_spent
1  sports       5
2  technology   8

hobby_types table

id name
33 computer
39 baseball
45 laptop

persons_hobbies join-table for person and hobbies

id person_id hobby_id
1  101      1
3  576      1
2  576      2

hobbies_hobby_types join-table for hobbies and hobby_types

hobby_id hobby_type_id 
1        39
2        33
3        45
  • 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-18T03:02:18+00:00Added an answer on May 18, 2026 at 3:02 am

    You are trying to get a so-called pivot table.

    I’m afraid there is no way to do it in MySQL with an unlimited number of columns, but maybe I’m wrong. Use your newly learned keyword to find a lot of information on this topic.

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

Sidebar

Related Questions

Does anyone know if it's possible to selected multiple days with swingx's jxdatepicker? I'm
I have an application that receives information from a database, and is used to
I'm looking for a google search module that uses the 'Google Custom Search API'
I've just had a massive *blonde moment** , but it's highlighted an annoyance I
A suite of data models built on top of Qt's reflection system seems like
NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which
I'm trying to add some Model properties into my JavaScript within my content page:
I am trying to measure how much data is sent and received by a
I am having an issue with Tomcat and Websphere when users try to login
I am often tasked with making specialty websites for the professors at my university.

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.