Fixing up database query to handle multiple results