mysql - Two SELECT's in one query in the same table -
i have 1 table:
id | parent_id | name 1 | null | audi 2 | 1 | a5 3 | 1 | a6 4 | null | opel 5 | 4 | astra 6 | 4 | vectra
i want name of record , name of record's parent.
one example fetch name id=5 , parent name.
id | name | parent_name 5 | astra | opel
what sql query this?
my query:
select name, parent_id `cats` `id` = 5 or `id` = cats.parent_id limit 0 , 30
didn't work.
you can use below query:
select t1.id, t1.name, t2.name parentname table1 t1 inner join table1 t2 on t1.id = t2.parent_id t2.id = 5
Comments
Post a Comment