There is a categories table and a category_type table with a link. I need to select categories from the categories table and select links from category_type for each one. I try this:

SELECT *, GROUP_CONCAT(category_type.type_id) as types FROM `categories` LEFT JOIN category_type on category_type.category_id = categories.id 

but as a result returns only those rows that have a link in the category_type table

  • one
    Without grouping, the request will return crap ... - Akina

1 answer 1

Magic

 SELECT categories.*, GROUP_CONCAT(category_type.type_id) as types FROM `categories` LEFT JOIN category_type on category_type.category_id = categories.id GROUP BY categories.id 
  • one
    Please describe what the problem was and why this code resolves it. - vp_arth
  • The problem is described in the question: "as a result, returns only those rows that have a link in the category_type table". Before writing a comment can read the question? - Jonny Manowar