Fixed query for null related columns.