Reputation:
I've a table:
Id | Name | ParentID
I want to select records whose parentid
not equal to zero, with parent record(parent record have parentid = 0
, but some parent record don't have child record I want to skip them )
Upvotes: 2
Views: 13799
Reputation: 55
Check this one:
select * from child c,parent p where c.ID=P.ParentID and c.ParentID !=0
Upvotes: 0
Reputation: 8558
Try this:
SELECT child.Id,
child.Name,
child.ParentId,
parent.Name as ParentName
FROM your_table child
JOIN your_table parent ON child.ParentId = parent.id;
Upvotes: 3