SELECT   DISTINCT purchase.id,purchase.permissions,purchase.status,purchaseCustomerInfo.firstName,purchaseCustomerInfo.lastName,purchase.created,requiresShipping,total    FROM purchase  INNER JOIN purchaseCustomerInfo ON purchase.id=purchaseCustomerInfo.purchaseId AND purchaseCustomerInfo.type IN('billing','both')    WHERE ( purchase.permissions LIKE 'r__' )        ORDER BY purchase.id DESC    LIMIT 0, 50