select xcart_products.*, xcart_products.avail -0 as avai, min(xcart_pricing.price) as price from ( xcart_products, xcart_pricing) left join xcart_avail on ''=xcart_avail.size and xcart_products.productid=xcart_avail.productid where xcart_products.productid= '' AND (xcart_categories.membership='' OR xcart_categories.membership='') and xcart_pricing.productid=xcart_products.productid and xcart_pricing.quantity=1 and (xcart_pricing.membership = '' or xcart_pricing.membership = '') group by xcart_products.productid