Views PHP Filter - Filter Results by Role
I would take the ORDER BY out of your last query and let views sort things itself. After all, you may want to sort the nids by date or something later on, so why do things twice?

And also change your query style to use the drupal syntax, like:

SELECT nid FROM {node}...