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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:18:01+00:00 2026-05-11T20:18:01+00:00

MySQL setup: step by step. programs -> linked to –> speakers (by program_id) At

  • 0

MySQL setup: step by step.

programs -> linked to –> speakers (by program_id)

At this point, it’s easy for me to query all the data:

SELECT * 
FROM programs 
JOIN speakers on programs.program_id = speakers.program_id

Nice and easy.

The trick for me is this. My speakers table is also linked to a third table, “books.” So in the “speakers” table, I have “book_id” and in the “books” table, the book_id is linked to a name.

I’ve tried this (including a WHERE you’ll notice):

SELECT *
FROM programs
JOIN speakers on programs.program_id = speakers.program_id
JOIN books on speakers.book_id = books.book_id
WHERE programs.category_id = 1
LIMIT 5

No results.

My questions:

  1. What am I doing wrong?
  2. What’s the most efficient way to make this query?

Basically, I want to get back all the programs data and the books data, but instead of the book_id, I need it to come back as the book name (from the 3rd table).

Thanks in advance for your help.

UPDATE:
(rather than opening a brand new question)

The left join worked for me. However, I have a new problem. Multiple books can be assigned to a single speaker.

Using the left join, returns two rows!! What do I need to add to return only a single row, but separate the two books.

  • 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-11T20:18:01+00:00Added an answer on May 11, 2026 at 8:18 pm

    is there any chance that the books table doesn’t have any matching columns for speakers.book_id?

    Try using a left join which will still return the program/speaker combinations, even if there are no matches in books.

    SELECT *
    FROM programs
    JOIN speakers on programs.program_id = speakers.program_id
    LEFT JOIN books on speakers.book_id = books.book_id
    WHERE programs.category_id = 1
    LIMIT 5
    

    Btw, could you post the table schemas for all tables involved, and exactly what output (or reasonable representation) you’d expect to get?

    Edit: Response to op author comment

    you can use group by and group_concat to put all the books on one row.

    e.g.

    SELECT speakers.speaker_id, 
           speakers.speaker_name, 
           programs.program_id, 
           programs.program_name,
           group_concat(books.book_name)
    FROM programs
    JOIN speakers on programs.program_id = speakers.program_id
    LEFT JOIN books on speakers.book_id = books.book_id
    WHERE programs.category_id = 1
    GROUP BY speakers.id
    LIMIT 5
    

    Note: since I don’t know the exact column names, these may be off

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your PHP output has a double byte-order-mark at the head.… May 13, 2026 at 1:50 am
  • Editorial Team
    Editorial Team added an answer Sounds to me like you might want viewWillAppear or viewDidAppear. May 13, 2026 at 1:50 am
  • Editorial Team
    Editorial Team added an answer You can make a union between the items before and… May 13, 2026 at 1:50 am

Related Questions

MySQL setup: step by step. programs -> linked to --> speakers (by program_id) At
I want to test some PHP on my local machine running Windows XP Professional.
I need to install mysql in my system in the first step After installing
What do I want to achieve? We are currently working on a PHP project
I have a form where the user selects field 1, and then selects field

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.