You need to decide how you want to order them.
SELECT p.*
FROM products p LEFT JOIN
categories AS c
ON c.cat_id = i.cat_id
ORDER BY c.`order` ASC;
MySQL happens to put the NULL
values first in an ascending sort. You probably want them last. So do this instead
SELECT p.*
FROM products p LEFT JOIN
categories AS c
ON c.cat_id = i.cat_id
ORDER BY (c.`order` is not null) DESC,
c.`order` ASC;
The expression (c.order is not null)
evaluates to 0
when order
is defined and to 1
when it is not.
And, order
is a very bad name for a column because it is a MySQL reserved word (actually, it is reserved in all databases). You might consider something like priority
instead.