Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am assuming that you are dealing with hierarchical data here.</p> <p>You just need two tables. One of the tables is for the categories and relationships between the categories. For example:</p> <pre><code>CategoryID CategoryName ParentCategoryID ---------------------------------------- 1 Computers NULL 2 Programming 1 3 Games 1 4 Python 2 </code></pre> <p>The other table is for storing the data associated with the categories. For example:</p> <pre><code>CategoryID ItemID Description ---------------------------------------------- 4 1 Book – Programming in Python 3 1 World of Warcraft </code></pre> <p>The first table contains a foreign key column that links the subcategories to their parent categories. This is known as the “Adjacency List Model”. This model has the advantage of being simple to understand and doing various things (e.g. retrieving the path to the Python category – /Computers/Programming/Python) with this model can be done quite easily with client-side code (if you don’t mind the performance cost because you may need to make multiple queries to the database). However, it can be mindboggling if you try to do it in full SQL. For example, retrieving the path for a category will require self-joins.</p> <p>Another way of structuring this table is to think of the categories and sub-categories as sets and subsets (known as the “Nested Set Model”). It’s hard to explain this model without diagrams, and the article <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow noreferrer">Managing Hierarchical Data in MySQL</a> seems to do a better job in explaining the concepts (both “Adjacency List” and “Nested Set” models).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload