Check to see if there are any matching ids before trying to use in SQL

This prevents a MySQL error