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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:18:45+00:00 2026-05-25T18:18:45+00:00

MySQL table_a: +—-+——-+ | id | title | +—-+——-+ Now I can do a

  • 0

MySQL “table_a”:

+----+-------+
| id | title |
+----+-------+

Now I can do a search like so:

$term = mysql_real_escape_string($_GET['term']);

mysql_query("SELECT * FROM `table_a`
WHERE MATCH(`title`) AGAINST('$term' IN BOOLEAN MODE) LIMIT 0,5");

However I want to add another compontent.

MySQL “table_b”:

+----+----------+
| id | category |
+----+----------+

MySQL “table_c”:

+------------+------------+
| table_a_id | table_b_id |
+------------+------------+

So, I want to look for a specific category in table_b that is linked to table_a according to table_c.

BUT, it isn’t always the case that a category is linked to table_a (so it could happen that there just aren’t any entries in table_c that are connected to table_a).

AND, if there is a category linked to table_a I want to be able to either search for the title in table_a or the category in table_b (so both should be possible, so category shouldn’t overrule title, or the other way around). But if that’s not possible, then title should overrule category.

Here’s what I came up with so far, but the problem is

a) it doesn’t work

b) it doesn’t include the title OR category as I had just explained

$term = mysql_real_escape_string($_GET['term']);

mysql_query("SELECT a.*, LEFT JOIN (SELECT c.table_a_id FROM table_b AS b
, table_c AS c WHERE b.category = '$term' AND b.id = c.table_b_id)
AS d ON d.table_a_id = a.id FROM table_a AS a
WHERE MATCH(a.title) AGAINST('$term' IN BOOLEAN MODE) LIMIT 0,5");

Any help would be greatly appreciated.

  • 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-25T18:18:46+00:00Added an answer on May 25, 2026 at 6:18 pm

    You really want to join the table_b and table_c data together and the perform your left join against that. Something like this should work for you. If there are multiple categories entries that match, you will have duplicate records, since you only want data from a.*. For debugging, I would add d.* as well so you can see why there are duplicates if there are any:

    SELECT a.*
    from   table_a a
           LEFT JOIN (SELECT c.table_a_id, b.category
                      from   table_b b,
                             table_c c
                      where  c.table_b_id = b.id) d
                      on     a.id = d.table_a_id
    WHERE d.category = '$_GET[term]'
    or    MATCH(a.title) AGAINST('$_GET[term]' IN BOOLEAN MODE) 
    LIMIT 0,5
    

    But, if you are doing anything other than testing, you absolutely have to escape the $_GET terms or, even better used parameterized SQL. If you aren’t familiar with creating prepared statements, see this StackOverflow answer.

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

Sidebar

Related Questions

I'm building a quick csv from a mysql table with a query like: select
Here is my current MySQL syntax (but this doesn't work): SELECT * FROM posts
Mysql: Table_A ------------ id name 1 Name1 2 Name2 Table_B ------------ a_id type value
I have a MySQL table with a column of well-formed URLs. I'd like to
I have a MySQL table (A) and I would like the end result to
I have a MySQL table from a third-party application that has millions of rows
I have a mysql table containing a field name dtt_date and have values like
I have a function that updates a MySQL table from a CSV file. The
I have a table showing information from a mysql table. I have three forms
How would you echo out a MySQL table into a html table. Like phpMyAdmin

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.