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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:08:24+00:00 2026-06-10T02:08:24+00:00

Hi guys i’ve been trying this sql search query to my website search facility

  • 0

Hi guys i’ve been trying this sql search query to my website search facility it supposed to search and order by relevance. It is working without the left join and I can’t get it to work with left join. Here is the SQL query.

SELECT bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
       bl_bands.bandpage as bandpage, sum(relevance)
FROM bl_albums 
LEFT JOIN(
  SELECT  bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
          bl_bands.bandpage as bandpage,10 AS relevance 
  FROM bl_albums 
  WHERE bl_albums.name like 'Camera'
  UNION
  SELECT bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
         bl_bands.bandpage as bandpage, 7 AS relevance 
  FROM bl_albums 
  WHERE bl_albums.name like 'Camera%'
  UNION
  SELECT  bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
          bl_bands.bandpage as bandpage, 5 AS relevance 
  FROM bl_albums 
  WHERE bl_albums.name like '%Camera'
  UNION
  SELECT bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
         bl_bands.bandpage as bandpage, 2 AS relevance 
  FROM bl_albums 
  WHERE bl_albums.name like '%Camera%'
)  bl_bands on bl_albums.bandid = bl_bands.id
GROUP BY bl_albums.name
ORDER BY relevance desc

all table names are correct and all column names are correct.

  • 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-10T02:08:25+00:00Added an answer on June 10, 2026 at 2:08 am

    Your subquery that you’ve named ‘bl_bands’ doesn’t have bl_bands.id because all the union joins don’t include the bl_bands table. Try adding joins to each union, if my assumption on all your data is correct:

    SELECT
        bl_albums.*,
        bl_bands.name as bandname,
        bl_bands.id as bandid, 
        bl_bands.bandpage as bandpage,
        sum(relevance)
    FROM
        bl_albums 
        LEFT JOIN(
          SELECT  bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
                  bl_bands.bandpage as bandpage,10 AS relevance 
          FROM bl_albums
            JOIN bl_bands ON bl_bands.id = bl_albums.bandid 
          WHERE bl_albums.name like 'Camera'
          UNION
          SELECT bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
                 bl_bands.bandpage as bandpage, 7 AS relevance 
          FROM bl_albums 
            JOIN bl_bands ON bl_bands.id = bl_albums.bandid
          WHERE bl_albums.name like 'Camera%'
          UNION
          SELECT  bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
                  bl_bands.bandpage as bandpage, 5 AS relevance 
          FROM bl_albums 
            JOIN bl_bands ON bl_bands.id = bl_albums.bandid
          WHERE bl_albums.name like '%Camera'
          UNION
          SELECT bl_albums.*, bl_bands.name as bandname, bl_bands.id as bandid, 
                 bl_bands.bandpage as bandpage, 2 AS relevance 
          FROM bl_albums 
            JOIN bl_bands ON bl_bands.id = bl_albums.bandid
          WHERE bl_albums.name like '%Camera%'
        ) bl_bands ON bl_albums.bandid = bl_bands.id
    GROUP BY bl_albums.name
    ORDER BY relevance desc
    

    It looks like you might have copied/pasted some SELECT statements/column names but didn’t add the joining in that you needed to get the results.

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

Sidebar

Related Questions

guys. I'm working on some audio services on iOS. I trying to search any
Guys I have been trying lots of different options from cutting up to building
Guys, this can't be for real I'm trying to make a .NET 2.0 executable
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
Guys this is driving me crazy.. I am amateur in the mod_rewrite topic.. I
guys. I've been searching for an answer for my issue the whole morning, but
Guys, I'm trying to write xpath or css to find/click on list element All
guys i have a xml file which is like this: <Point TestFlag=0 id=1 name=Conversation
guys, I'm trying to realize viewing comments on internet portal and I'm using UITableView.

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.