0
SELECT
    categories.id, categories.name
AS
    parentName
FROM
    categories
INNER JOIN
    categories
ON
    categories.parent = categories.id
ORDER BY
    id
DESC

I want to inner join two columns in same table (categories).

Rahul
  • 76,197
  • 13
  • 71
  • 125
Alaa Nabawii
  • 65
  • 1
  • 7
  • 1
    Possible duplicate of [Why does this SQL code give error 1066 (Not unique table/alias: 'user')?](https://stackoverflow.com/questions/1435177/why-does-this-sql-code-give-error-1066-not-unique-table-alias-user) – philipxy Oct 13 '17 at 08:03
  • Hi. This is a faq. Next time start with google. – philipxy Oct 13 '17 at 08:03

1 Answers1

1

That's 'cause you are joining on the same table, which needs a table alias in order to avoid confusion, as illustrated below

FROM
    categories
INNER JOIN
    categories

Change it to below (here c1, c2 are table aliases)

FROM
    categories c1
INNER JOIN
    categories c2 
ON
    c1.parent = c2.id

and adjust the SELECT clause accordingly

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Rahul
  • 76,197
  • 13
  • 71
  • 125