Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider this example...</p> <pre><code> DROP TABLE IF EXISTS comments; CREATE TABLE comments (comment_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,comment VARCHAR(50) NOT NULL ,comment_date DATETIME ,parent_id INT NULL ); INSERT INTO comments VALUES (1 ,'Hello', '2013-03-01 10:10:10',NULL), (2 ,'Bonjour', '2013-03-02 10:10:10',NULL), (3 ,'How are you?', '2013-03-03 10:10:10',1), (4 ,'I\'m fine thank you, and you?', '2013-03-04 10:10:10',1), (5 ,'Ça va?', '2013-03-05 10:10:10',2), (6 ,'Je vais bien, merci, et toi?', '2013-03-06 10:10:10',2), (7 ,'Yes, not too bad thanks', '2013-03-07 10:10:10',1), (8 ,'Oui, comme ci comme ça.', '2013-03-08 10:10:10',2), (9 ,'Bon, à bientôt.', '2013-03-09 10:10:10',2), (10 ,'See you soon', '2013-03-10 10:10:10',1); SELECT * FROM comments x JOIN comments y ON y.parent_id = x.comment_id ORDER BY x.comment_date , y.comment_date; +------------+---------+---------------------+-----------+------------+------------------------------+---------------------+-----------+ | comment_id | comment | comment_date | parent_id | comment_id | comment | comment_date | parent_id | +------------+---------+---------------------+-----------+------------+------------------------------+---------------------+-----------+ | 1 | Hello | 2013-03-01 10:10:10 | NULL | 3 | How are you? | 2013-03-03 10:10:10 | 1 | | 1 | Hello | 2013-03-01 10:10:10 | NULL | 4 | I'm fine thank you, and you? | 2013-03-04 10:10:10 | 1 | | 1 | Hello | 2013-03-01 10:10:10 | NULL | 7 | Yes, not too bad thanks | 2013-03-07 10:10:10 | 1 | | 1 | Hello | 2013-03-01 10:10:10 | NULL | 10 | See you soon | 2013-03-10 10:10:10 | 1 | | 2 | Bonjour | 2013-03-02 10:10:10 | NULL | 5 | Ça va? | 2013-03-05 10:10:10 | 2 | | 2 | Bonjour | 2013-03-02 10:10:10 | NULL | 6 | Je vais bien, merci, et toi? | 2013-03-06 10:10:10 | 2 | | 2 | Bonjour | 2013-03-02 10:10:10 | NULL | 8 | Oui, comme ci comme ça. | 2013-03-08 10:10:10 | 2 | | 2 | Bonjour | 2013-03-02 10:10:10 | NULL | 9 | Bon, à bientôt. | 2013-03-09 10:10:10 | 2 | +------------+---------+---------------------+-----------+------------+------------------------------+---------------------+-----------+ </code></pre>
    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.
 

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