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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:28:59+00:00 2026-05-15T12:28:59+00:00

So, I’ve got a webapp that lets users submit code. The submissions are stored

  • 0

So, I’ve got a webapp that lets users submit code. The submissions are stored in the code table, and a couple of columns of that are Fulltext-Indexed. This is how I have been performing searches up until now.

But, users can submit their submissions with as many tags as they like – and I’d like these to be included in the search too (but, all in one query…). The tags are stored in the table tags, and there’s an intersection table called code_tags that stores the code_id and the tag_id. Standard stuff.

My ‘old’ search query was this:

SELECT *
  FROM code
 WHERE MATCH (title, summary, code) AGAINST ('$searchterm')

$searchterm was fetched via PHP $_POST.

So I tried to write a bit more of an ‘advanced’ query:

SELECT code.*, 
       code_tags.*, 
       tags.*, 
       tags.tag
  FROM code, code_tags, tags
 WHERE code_tags.code_id = code.id
   AND tags.id = code_tags.tag_id
   AND MATCH (title, summary, code) AGAINST ('$searchterm') 

But all this did was return… nothing. Even when a perfectly valid search term was entered.

So I commented out the last line:

SELECT code.*, code_tags.*, tags.*, tags.tag
  FROM code, code_tags, tags
 WHERE code_tags.code_id = code.id
   AND tags.id = code_tags.tag_id
-- AND MATCH (title, summary, code) AGAINST ('php') 

This returns every submission in the database. But, the same row is repeated as many times as there are tags for it (the only difference being, the tag in each returned row).

E.G:

Query Fail

So, finally, I thought I’d be clever and GROUP_CONCAT the tags:

SELECT code.*, code_tags.*, tags.*, GROUP_CONCAT(tags.tag SEPARATOR ' ') AS taggroup
  FROM code, code_tags, tags
 WHERE code_tags.code_id = code.id
   AND tags.id = code_tags.tag_id
-- AND MATCH (title, summary, code, taggroup) AGAINST ('php')`

There are two pretty big problems with this.

  1. With the last AND MATCH line commented out, only one row is returned (with all the details of the first entry in the code table – and taggroup lists every tag, for every submission!
  2. With the last AND MATCH line included, I get the following error: Unknown column 'taggroup' in 'where clause' – damn!

So, what am I meant to do? :S

  • 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-15T12:28:59+00:00Added an answer on May 15, 2026 at 12:28 pm

    The reason the following:

    SELECT code.*, code_tags.*, tags.*, tags.tag
      FROM code, code_tags, tags
     WHERE code_tags.code_id = code.id
       AND tags.id = code_tags.tag_id
       AND MATCH (title, summary, code) AGAINST ('php') 
    

    …doesn’t return any results is that you don’t have any code table records whose title/summary/code match “php” AND have relations to either the CODE_TAGS or TAGS tables. Switching to ANSI-92 JOIN syntax, try:

    SELECT c.*, ct.*
      FROM CODE c
      JOIN CODE_TAGS ct ON ct.code_id = c.id
     WHERE MATCH (title, summary, code) AGAINST ('php')
    

    If nothing is returned, then you’re problem is that none of the records that satisfy the Full Text Search are related to anything in the CODE_TAGS table — you’ll need to add associations before it will work. That should shine some light on if adding the JOIN to the TAGS table will affect anything:

    SELECT c.*, ct.*
      FROM CODE c
      JOIN CODE_TAGS ct ON ct.code_id = c.id
      JOIN TAGS t ON t.id = ct.tag_id
     WHERE MATCH (title, summary, code) AGAINST ('php')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • 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 I tried to run the statement in my questition via… May 15, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer <script type="text/javascript"> $(document).ready(function() { $('#upload').bind("click",function() { var imgVal = $('#uploadImage').val();… May 15, 2026 at 7:56 pm
  • Editorial Team
    Editorial Team added an answer You can try using critical sections. See the wiki page… May 15, 2026 at 7:56 pm

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.