I have a table which has categories information.
The table has a field to mark the parent and child categories.
I tried to list the parent category then its child category through a query.
I tried something like
SELECT
CategoryID.categories as ParentID,
CategoryName.categories AS ParentName,
parents.*
FROM
categories AS parents LEFT JOIN categories AS child
ON child.Parent = parents.ParentID
but unfortunately it didn’t work for me. It gives me a weird error.
[SQL] SELECT CategoryID.categories as ParentID, CategoryName.categories
AS ParentName, parents.* FROM categories as parents LEFT JOIN categories as child on child.Parent = parents.ParentID
[Err] 1054 - Unknown column 'CategoryID.categories' in 'field list'
and I’m sure that all fields name are correct.
First thing is, db engine reads columns [table].[column], not the other way around. So it won’t understand what CategoryID.categories is – there is no table called CategoryID.
You defined your tables as such
So you need to reference them using the names you gave them. i.e.