List records grouped by category name

前端 未结 2 640
-上瘾入骨i
-上瘾入骨i 2021-01-22 14:12

I am having some problems, trying to get data from my database, and show it correctly. I have a layout, where I have two \"lists\", where I can add rows to each lists. I can add

2条回答
  •  执念已碎
    2021-01-22 14:44

    If you run a SQL query and you want the results in a particular order, then ALWAYS include an order by clause.

    In your case, you seem to want:

    SELECT dl.id, dl.list_id, dl.date, dl.list_name,
           dls.*
    FROM driving_lists dl LEFT JOIN
         driving_list_shipments dls
         ON dl.list_id = dls.list_id
    ORDER BY dl.list_id;
    

    I assume that list_id is what you mean by list_id.

    I should note that you have list_id appearing twice in the SELECT, because it is in both tables. You should probably explicitly list the columns you want from both tables, and avoid redundant columns.

提交回复
热议问题