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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:40:12+00:00 2026-06-07T10:40:12+00:00

Having troubles adding a LEFT JOIN & INNER JOIN, combined, to an existing query.

  • 0

Having troubles adding a LEFT JOIN & INNER JOIN, combined, to an existing query.

I have two main tables; “photoSearch” containing all searchable data for my photos, and “photos”, containing all data for my photos. I am using FULLTEXT across 3 fields in “photoSearch” to get relevant photoID’s and then grabs the data from the “photos” table, like copyrights, sizes, dimensions…

This is my query:

SELECT p.photoID, p.setID, p.headline, p.caption, p.height, p.width, p.size, p.copyright
FROM photos AS p,
      (SELECT photoID FROM photoSearch WHERE MATCH (allPeople, allKeywords, shortCaption)
      AGAINST ('+byline' IN BOOLEAN MODE) LIMIT 0,50) AS photoIDs
WHERE p.photoID = photoIDs.photoID;

I now need to modify this query to include a LEFT JOIN and an INNER JOIN which gets any names of people shown in each photo, to print on-screen. Some photos do not have any people, hence needing a LEFT JOIN. I have this data across two tables (normalized); “photoPeople” and “people”, so I came up with this join:

My Join (which needs adding to the above query)

LEFT JOIN ( photoPeople AS pp INNER JOIN people AS pe ON pp.peopleID = pe.PeopleID)
ON p.photoID = pp.photoID

But I’m finding it hard to fit it in my original query, as the sub-select query is in the comma delimited FROM list – it’s confusing me. I also want to make sure that I’m not affecting the performance of the FULLTEXT index by joining where I shouldn’t.

I did try adding it straight after the sub-select (before WHERE) but I was getting SQL errors saying it did not recognise column p.photoID.

Both original query and the DB design is not mine.

Any help or guidance would be gratefully received.

  • 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-07T10:40:14+00:00Added an answer on June 7, 2026 at 10:40 am
    SELECT 
        p.photoID, 
        p.setID, 
        p.headline, 
        p.caption, 
        p.height, 
        p.width, 
        p.size, 
        p.copyright,
        pe.*
    FROM 
        photos p
    INNER JOIN
        (
            SELECT photoID 
            FROM photoSearch 
            WHERE MATCH (allPeople, allKeywords, shortCaption) AGAINST ('+byline' IN BOOLEAN MODE) 
            LIMIT 50
        ) pids ON p.photoID = pids.photoID
    LEFT JOIN
        photoPeople pp ON p.photoID = pp.photoID
    LEFT JOIN
        people pe ON pp.peopleID = pe.peopleID
    

    I don’t see a need to INNER JOIN the people table on the LEFT JOIN because if the LEFT JOIN is NULL, the people will also be NULL

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

Sidebar

Related Questions

I am having trouble adding ajax functionality to existing asp.net 4 website. I have
I am having a trouble adding left padding on a UIButton . I have
I'm trying to match up two bits of data, adding to an existing query.
I am trying to perform a simple join on two tables and am having
I am new to Objective C and am having troubles adding a 2d int
im having troubles with adding a class to the last option from foreach, its
I'm having some troubles adding an UIView to cocos2d v2.0 since the openGlView is
I'm having troubles adding font-family to a predefined HTML structure with content in itextsharp.
I am having real troubles adding a UIImageView to a single UITableView cell. In
I'm having trouble adding a where clause to this query. I would like it

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.