how to get row field for each node
The error is in your php snippet. You request all rows, but $query-&gt;fetchObject(); only returns the first one, as you do not iterate over them.
Use something like $query-&gt;fetchAll() or $query-&gt;fetchAllAssoc('domain_id'); instead to access all rows.

But, I think there must be smarter ways to handle this. Can't you add a relationship from the node to the domain? (I never used domain before). Such relationship would give you the domain entity associated with the node, so you always have the right one.