order sql tree hierarchy

前端 未结 8 1551
野的像风
野的像风 2020-12-05 03:30

What is the best way to sort a table like this:

CREATE TABLE category(
    id INT(10),
    parent_id INT(10),
    name VARCHAR(50)
);

INSERT INTO category (         


        
8条回答
  •  隐瞒了意图╮
    2020-12-05 03:49

    Try ORDER BY name , id at the end of your SQL query.

    This will sort by name and use id to settle any ties.

提交回复
热议问题