SELECT
	pd.id as id,
	pd.purchase_id as purchase_id,
	pd.purchase_sub_code as seq_number,
	pd.product_barcode as product_barcode,
	ps.product_category_id as product_category_id,
	pd.product_set_id as product_set_id,
	pd.product_model_id as product_id,
	pd.lot_number as lot_number,
	'' as serial_number,
	pd.ubd_date as ubd,
	24 as validity_period,
	1 as unit_code,
	pd.purchase_quantity as quantity,
	pd.purchase_quantity as scheduled_quantity,
	pd.purchase_price as price,
	NULL as products_price_id,
	NULL as stock_type_code,
	0 as inspect_status_code,
	pd.purchase_detail_note as note,
	NOW() as created_at,
	NOW() as updated_at
FROM purchase_details as pd 
LEFT JOIN master_app_production.product_sets as ps
  ON pd.product_set_id = ps.id
WHERE pd.purchase_id > 1653
INTO OUTFILE "/tmp/purchase_details.csv" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';