| SELECT `Diamond`.`id`, `Diamond`.`sku`, `Diamond`.`type_id`, `Diamond`.`lab_id`, `Diamond`.`report`, `Diamond`.`source_id`, `Diamond`.`xsku`, `Diamond`.`is_stock`, `Diamond`.`is_available`, `Diamond`.`is_visible`, `Diamond`.`is_hidden`, `Diamond`.`wdays`, `Diamond`.`xorder_id`, `Diamond`.`product_id`, `Diamond`.`shape_id`, `Diamond`.`carats`, `Diamond`.`color_id`, `Diamond`.`clarity_id`, `Diamond`.`cut_id`, `Diamond`.`polish_id`, `Diamond`.`symmetry_id`, `Diamond`.`fluorescence_id`, `Diamond`.`length`, `Diamond`.`width`, `Diamond`.`height`, `Diamond`.`depth_percent`, `Diamond`.`table_percent`, `Diamond`.`has_photo`, `Diamond`.`photo`, `Diamond`.`has_video`, `Diamond`.`video`, `Diamond`.`has_certi`, `Diamond`.`certi`, `Diamond`.`contents`, `Diamond`.`created`, `Diamond`.`timestamp`, (`Diamond`.`sku`) AS `Diamond__display_field`, ((SELECT COUNT(*) + 1 FROM diamonds Diamond_Diamonds WHERE `Diamond`.`xorder_id` = `Diamond_Diamonds`.`xorder_id` AND `Diamond`.`sku` > `Diamond_Diamonds`.`sku`)) AS `Diamond__xorder_pos`, (`Diamond`.`price`) AS `Diamond__price`, (`Diamond`.`cost`) AS `Diamond__cost`, ((SELECT `Diamond_Xorder`.`exchange_rate` FROM xorders Diamond_Xorder WHERE `Diamond`.`xorder_id` = `Diamond_Xorder`.`id`)) AS `Diamond__exchange_rate`, (1) AS `Diamond__profit`, (1) AS `Diamond__profit_percent`, `Source`.`id`, `Source`.`code`, `Source`.`name`, `Source`.`speed`, `Source`.`is_fast`, (`Source`.`name`) AS `Source__display_field`, `Xorder`.`id`, `Xorder`.`partner_id`, `Xorder`.`date`, `Xorder`.`awb`, `Xorder`.`currency`, `Xorder`.`exchange_rate`, `Xorder`.`notes`, `Xorder`.`created`, `Xorder`.`timestamp`, (CONCAT(`Xorder`.`date`, " ", (SELECT `Xorder_Partner`.`name` FROM partners Xorder_Partner WHERE `Xorder`.`partner_id` = `Xorder_Partner`.`id`))) AS `Xorder__display_field`, (IFNULL((SELECT SUM(`Xorder_Diamonds`.`cost`) FROM diamonds Xorder_Diamonds WHERE `Xorder`.`id` = `Xorder_Diamonds`.`xorder_id`), 0)) AS `Xorder__diamonds_cost`, ((IFNULL((SELECT SUM(`Xorder_Diamonds`.`cost`) FROM diamonds Xorder_Diamonds WHERE `Xorder`.`id` = `Xorder_Diamonds`.`xorder_id`), 0) + `Xorder`.`ship_cost`)) AS `Xorder__xpayment_xamount`, (ROUND(`Xorder`.`ship_cost` * `Xorder`.`exchange_rate`, 2)) AS `Xorder__ship_cost`, (ROUND(100 * ROUND(`Xorder`.`ship_cost` * `Xorder`.`exchange_rate`, 2) / IFNULL((SELECT SUM(`Xorder_Diamonds`.`cost`) FROM diamonds Xorder_Diamonds WHERE `Xorder`.`id` = `Xorder_Diamonds`.`xorder_id`), 0), 2)) AS `Xorder__ship_cost_percent`, `Product`.`id`, `Product`.`order_id`, `Product`.`design_id`, `Product`.`is_w`, `Product`.`size`, `Product`.`width`, `Product`.`engraving`, `Product`.`grams`, `Product`.`price`, `Product`.`print_op_id`, `Product`.`cast_op_id`, `Product`.`created`, `Product`.`timestamp`, (CONCAT((SELECT TRIM(CONCAT(`Product_Order`.`customer`, " ", `Product_Order`.`last_name`)) FROM orders Product_Order WHERE `Product`.`order_id` = `Product_Order`.`id`), " P#", `Product`.`id`)) AS `Product__display_field`, ((`Product`.`price` + IFNULL((SELECT SUM(`Product_Diamonds`.`price`) FROM diamonds Product_Diamonds WHERE `Product`.`id` = `Product_Diamonds`.`product_id`), 0) + IFNULL((SELECT SUM((SELECT `DiamondRequest_Diamond`.`price` FROM diamonds DiamondRequest_Diamond WHERE `Product_DiamondRequests`.`diamond_id` = `DiamondRequest_Diamond`.`id`)) FROM diamond_requests Product_DiamondRequests WHERE `Product`.`id` = `Product_DiamondRequests`.`product_id`), 0) + IFNULL((SELECT SUM(ROUND(ROUND(`Product_ProductGemstones`.`quantity` * (SELECT `ProductGemstone_Gemstone`.`carats` FROM gemstones ProductGemstone_Gemstone WHERE `Product_ProductGemstones`.`gemstone_id` = `ProductGemstone_Gemstone`.`id`), 2) * `Product_ProductGemstones`.`carat_price`)) FROM product_gemstones Product_ProductGemstones WHERE `Product`.`id` = `Product_ProductGemstones`.`product_id`), 0))) AS `Product__total_price`, (IFNULL((SELECT SUM((SELECT `DiamondRequest_Diamond`.`price` FROM diamonds DiamondRequest_Diamond WHERE `Product_DiamondRequests`.`diamond_id` = `DiamondRequest_Diamond`.`id`)) FROM diamond_requests Product_DiamondRequests WHERE `Product`.`id` = `Product_DiamondRequests`.`product_id`), 0)) AS `Product__diamond_requests_price`, `Shape`.`id`, `Shape`.`code`, `Shape`.`name`, `Shape`.`long_name`, `Shape`.`description`, (`Shape`.`name`) AS `Shape__display_field`, `Color`.`id`, `Color`.`code`, `Color`.`description`, (`Color`.`code`) AS `Color__display_field`, `Clarity`.`id`, `Clarity`.`code`, `Clarity`.`name`, `Clarity`.`description`, (`Clarity`.`code`) AS `Clarity__display_field`, `Cut`.`id`, `Cut`.`code`, `Cut`.`name`, `Cut`.`description`, (`Cut`.`code`) AS `Cut__display_field`, `Polish`.`id`, `Polish`.`code`, `Polish`.`name`, (`Polish`.`code`) AS `Polish__display_field`, `Symmetry`.`id`, `Symmetry`.`code`, `Symmetry`.`name`, (`Symmetry`.`code`) AS `Symmetry__display_field`, `Fluorescence`.`id`, `Fluorescence`.`code`, `Fluorescence`.`name`, (`Fluorescence`.`code`) AS `Fluorescence__display_field` FROM `giuvaier_d`.`diamonds` AS `Diamond` LEFT JOIN `giuvaier_d`.`sources` AS `Source` ON (`Diamond`.`source_id` = `Source`.`id`) LEFT JOIN `giuvaier_d`.`xorders` AS `Xorder` ON (`Diamond`.`xorder_id` = `Xorder`.`id`) LEFT JOIN `giuvaier_d`.`products` AS `Product` ON (`Diamond`.`product_id` = `Product`.`id`) LEFT JOIN `giuvaier_d`.`shapes` AS `Shape` ON (`Diamond`.`shape_id` = `Shape`.`id`) LEFT JOIN `giuvaier_d`.`colors` AS `Color` ON (`Diamond`.`color_id` = `Color`.`id`) LEFT JOIN `giuvaier_d`.`clarities` AS `Clarity` ON (`Diamond`.`clarity_id` = `Clarity`.`id`) LEFT JOIN `giuvaier_d`.`cuts` AS `Cut` ON (`Diamond`.`cut_id` = `Cut`.`id`) LEFT JOIN `giuvaier_d`.`polishes` AS `Polish` ON (`Diamond`.`polish_id` = `Polish`.`id`) LEFT JOIN `giuvaier_d`.`symmetries` AS `Symmetry` ON (`Diamond`.`symmetry_id` = `Symmetry`.`id`) LEFT JOIN `giuvaier_d`.`fluorescences` AS `Fluorescence` ON (`Diamond`.`fluorescence_id` = `Fluorescence`.`id`) WHERE ((NOT (`Diamond`.`xorder_id` IS NULL)) AND (`Diamond`.`product_id` IS NULL)) ORDER BY `Diamond`.`xorder_id` asc LIMIT 20 | 6 | 6 | 18 | maybe slow |