Let me understand this:
You have two tables: like
category
id
name
and
categoryrelationships
parentid
childid
And you want to write a query to
SELECT *
FROM categoryrelationships
WHERE parentid=0
??
How do you have records in the categoryrelationships table where the record has no parent id?
Perhaps what you mean to say is:
I want to
SELECT *
FROM category
categories not present in the categoryrelationship table
So you'll want to JOIN those tables -- specifically a LEFT JOIN. You want to return category records (even if there are no categoryrelationship records -- in fact SPECIFICALLY when there are no category relationship records).
SELECT category.*
FROM category
LEFT JOIN categoryrelationship ON category.id=categoryrelationships.parentid
That gets you all the category records, and the relationships where they are the parentid (or not)
But you only want the "orphan" categories
SELECT category.*
FROM category
LEFT JOIN categoryrelationship ON category.id=categoryrelationships.parentid
WHERE categoryrelationships.parentid IS NULL