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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T08:56:58+00:00 2026-05-19T08:56:58+00:00

I have the following schema on MySQL 5.1 CREATE TABLE `mytest` ( `category` varchar(32)

  • 0

I have the following schema on MySQL 5.1

CREATE TABLE  `mytest` (
  `category` varchar(32) ,
  `item_name` varchar(255)
  KEY `key1` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; 

category column is filled with like that

[:parent_parent_cat_id][:parent_cat_id][:leaf_cat_id]

10000200003000

if you can search all of the under categories :parent_parent_category_id

SELECT * FROM mytest WHERE category LIKE "10000%";

it’s using index key1;

but
How to use index when I wanna search :parent_cat_id?

SELECT * FROM mytest WHERE category LIKE "%20000%";

Do you have a better solutions?

  • 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-19T08:56:58+00:00Added an answer on May 19, 2026 at 8:56 am

    This model is called materialized path.

    You just need to categories in a separate table and make items reference that table instead, not the path:

    SELECT  i.*
    FROM    categories c
    JOIN    items i
    ON      i.category = c.id
    WHERE   c.path BETWEEN
            (
            SELECT  path
            FROM    categories ci
            WHERE   ci.id = '20000'
            )
            AND
            CONCAT(
            (
            SELECT  path
            FROM    categories ci
            WHERE   ci.id = '20000'
            ), ':')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following pseudo-SQL schema: table flight id int primary key date timestamp
Given the following schema: CREATE TABLE players ( id BIGINT PRIMARY KEY, name TEXT
I have a MySQL table with the following schema: +---------+---------+----------------------+------------+ | User ID |
I have a table with the following schema in MySql 5.1: Venue (id, name,
I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a bunch of coordinates in my table grid with the following schema
I have no control over database schema and have the following (simplified) table structure:
I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .
I have a table with the following schema: +------------------+ |Field | Type | +------------------+
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,

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.