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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:18:45+00:00 2026-06-14T15:18:45+00:00

I have to create a table in the way shown below. Can we create

  • 0

I have to create a table in the way shown below. Can we create in this way? (If Yes)

Table_name: Sample

product_id|   product_name| category   |
    1     |   Sample1     |  1|2|3     |
    2     |   sample2     |  4|5|6     |

where category filed which contains multiple values.

& how we can search for category 4 comes in which row of the table.

  • 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-14T15:18:46+00:00Added an answer on June 14, 2026 at 3:18 pm

    You cannot create nested table. And the thing on your mind is not a good idea to design table like that. You should have two tables (exactly three which holds the description if the category). One is for the product and the second table holds the category for each product. Example design would look like this,

    CREATE TABLE Product
    (
        ProductID INT PRIMARY KEY,
        ProductName VARCHAR(50) UNIQUE
    );
    
    CREATE TABLE Category
    (
        CategoryID INT PRIMARY KEY,
        CategoryName VARCHAR(50) UNIQUE
    );
    
    CREATE TABLE Product_Category
    (
        RecordD INT AUTO_INCREMENT PRIMARY KEY,
        CategoryID INT,
        ProductID INT,
        CONSTRAINT tb_uq UNIQUE(CategoryID, ProductID)
    );
    

    and Populate Sample Records

    INSERT Category VALUES (1, 'Fruit');
    INSERT Category VALUES (2, 'Vegetable');
    
    INSERT Product VALUES (1, 'Apple');
    INSERT Product VALUES (2, 'Banana');
    INSERT Product VALUES (3, 'Cabbage');
    INSERT Product VALUES (4, 'Squash');
    INSERT Product VALUES (5, 'Tomato');
    
    INSERT Product_Category (CategoryID, ProductID) VALUES (1,1);
    INSERT Product_Category (CategoryID, ProductID) VALUES (1,2);
    INSERT Product_Category (CategoryID, ProductID) VALUES (2,3);
    INSERT Product_Category (CategoryID, ProductID) VALUES (2,4);
    INSERT Product_Category (CategoryID, ProductID) VALUES (1,5);
    INSERT Product_Category (CategoryID, ProductID) VALUES (2,5);
    
    • SQLFiddle Demo (with records included)

    sample queries

    -- NORMAL QUERY
    SELECT  a.ProductName, c.CategoryName
    FROM    Product a
            INNER JOIN Product_category b
              ON a.ProductID = b.ProductID
            INNER JOIN Category c
              ON b.CategoryID = c.CategoryID
    ORDER BY ProductName;
    
    -- If you want catgoryName to be comma separated
    SELECT  a.ProductName, GROUP_CONCAT(c.CategoryName) CategoryList
    FROM    Product a
            INNER JOIN Product_category b
              ON a.ProductID = b.ProductID
            INNER JOIN Category c
              ON b.CategoryID = c.CategoryID
    GROUP BY ProductName
    ORDER BY ProductName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
i have this table create table eveniment( + evenimentId bigint not null auto_increment primary
This is my current schema - shown partially. CREATE TABLE cart ( username VARCHAR(60),
I am new to iphone.I have a small doubt (i.e),I have create a table
I have a table: CREATE TABLE siteConfig ( settingName VARCHAR(64) NOT NULL, value VARCHAR(255),
I have a table CREATE TABLE `messages` ( `uid` BIGINT NOT NULL , `mid`
I have a table Create table Country_State_Mapping ( Country nvarchar(max), State nvarchar(max) ) With

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.