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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:48:45+00:00 2026-05-23T16:48:45+00:00

I have a table products (id, barcode, catid, name, description, …) and I’ve been

  • 0

I have a table products (id, barcode, catid, name, description, …) and I’ve been asked to make it possible that some products can be assigned to more than one categories.
The most obvious solution would be to change catid from INT to VARCHAR with delimited values ie 1,2,5 where 1,2 & 5 are the various categories.

Which SQL statement will do the job for me now? I have find_in_set in mind but I think it does the opposite.

  • 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-23T16:48:46+00:00Added an answer on May 23, 2026 at 4:48 pm

    The most obvious solution would be to create a ‘cross-table’ where you can do a many-to-many assignment (as in one category can have many products and one product can have many categories). This table would look like this:

    product_id | category_id
    

    You can then use this query:

    SELECT 
      *
    FROM 
      (product JOIN product_has_category ON product.id = product_has_category.product_id) 
          JOIN category ON product_has_category.category_id = category.id
    

    You can even use normal WHERE and `ORDER BY, etc.

    edit: Fixed a major error in my query, my appologies!


    If you are unable to change the database, you might want to try this:

    SELECT 
      *
    FROM 
      category, product
    WHERE
      product.id = ?? AND FIND_IN_SET(category.id, product.catid) > 0 GROUP BY product.id
    

    Warning: It is a long shot, I haven’t tested this, but as FIND_IN_SET would search a comma-seperated list, it could work.

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

Sidebar

Related Questions

I have a table 'products' => ('product_id', 'name', 'description') and a table 'product_price' =>
I have 3 tables Table: Products productid (int) name (varchar) description (text) Table: Sales
So imagine that you have a table of Products (ID int, Name nvarchar(200)) ,
I have a products table that contains a FK for a category, the Categories
Hello i have a products table that contains normal products and configurable product It
I have a SQL Server DB that has a table of products, and another
I have a table Products. Products: id Name category 1 Sony Bravia TV 2
Here is my problem. For example I have a table Products that contains a
I have a product table called products It has 3 fields (name,model(PK), and class_name).
I have a table with products that have columns like this: price[decimals 8,5] and

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.