Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@Abiel, Based on your comment that each node probably doesn't have more than 50 direct children, and in that case (where 62 child nodes will be enough)—as @Bohemian stated on the comment—we could use computer-readable code <code>0-9A-Za-z</code> (<a href="http://en.wikipedia.org/wiki/Base_62" rel="nofollow">Base 62 Encoding</a>), we could set a new <code>VARCHAR( 255 ) BINARY</code> column to help us with sorting.</p> <pre><code>CREATE TABLE `test`.`tree` ( `computer_readable` VARCHAR( 255 ) BINARY NOT NULL , `human_readable` VARCHAR( 255 ) NOT NULL , `title` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `computer_readable` ) , INDEX ( `human_readable` ) ); </code></pre> <p>As you might already noticed, the <code>computer_readable</code> column is defined as <code>BINARY</code>, so we could have up to 62 <code>[0-9A-Za-z]</code> (instead of 36 <code>[0-9a-z]</code>) child nodes for each node. </p> <pre><code>mysql&gt; SELECT 'a' = 'A'; +-----------+ | 'a' = 'A' | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec) mysql&gt; SELECT BINARY 'a' = 'A'; +------------------+ | BINARY 'a' = 'A' | +------------------+ | 0 | +------------------+ 1 row in set (0.00 sec) mysql&gt; SELECT BINARY 'a' &gt; 'A'; +------------------+ | BINARY 'a' &gt; 'A' | +------------------+ | 1 | +------------------+ 1 row in set (0.00 sec) </code></pre> <p>So, with this new field, we could have the data in this format (stated in CSV below):</p> <pre><code>"1";"1";"Books" "11";"1.1";"Fiction" "111";"1.1.1";"Science-Fiction" "12";"1.2";"Self-Help" "121";"1.2.1";"Motivational" "1A";"1.10";"Textbooks" "1e";"1.40";"Coloring Books" "2";"2";"Music" "21";"2.1";"Classical" </code></pre> <p>Which MySQL will happily sort for us</p> <pre><code>mysql&gt; SELECT * FROM `tree` ORDER BY `computer_readable`; +-------------------+----------------+-----------------+ | computer_readable | human_readable | title | +-------------------+----------------+-----------------+ | 1 | 1 | Books | | 11 | 1.1 | Fiction | | 111 | 1.1.1 | Science-Fiction | | 12 | 1.2 | Self-Help | | 121 | 1.2.1 | Motivational | | 1A | 1.10 | Textbooks | | 1e | 1.40 | Coloring Books | | 2 | 2 | Music | | 21 | 2.1 | Classical | +-------------------+----------------+-----------------+ 9 rows in set (0.00 sec) </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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