Lia97
2 months ago

How this query works for Eloquent

Posted 2 months ago by Lia97

I have a query like this. How should I convert it into a eloquent or query builder

SELECT x.MATERIAL_ID, (SELECT TAPET_NAME FROM MA_TAPE_TYPE WHERE TAPET_CODE = x.MATERIAL_TYPE) as media_type, (SELECT TAPEF_NAME FROM MA_TAPE_FORMAT WHERE TAPEF_CODE = x.MATERIAL_FORMAT) as media_format, STOCK_MATERIAL_EPI.HOUSE_NO, x.TXN_DATE, STOCK_MATERIAL_EPI.PROGRAM_NAME, CASE WHEN x.iden_flag = 'P' THEN STOCK_MATERIAL_EPI.epi_title WHEN x.iden_flag = 'C' THEN STOCK_MATERIAL_EPI.prod_version_name WHEN x.iden_flag = 'M' THEN STOCK_MATERIAL_EPI.promo_name END as episode_title, PUR_EPISODE_HDR.EPI_NO, (SELECT MAX (last_date) FROM run_master WHERE run_master.row_id_epi = PUR_EPISODE_HDR.row_id AND run_master.run_aired = 'Y') as last_tx, x.REMARKS, x.LOCATION_ID as shelf_no, stock_material_slag.remarks as short_list FROM STOCK_MATERIAL x LEFT JOIN STOCK_MATERIAL_EPI ON x.MATERIAL_ID = STOCK_MATERIAL_EPI.MATERIAL_ID LEFT JOIN stock_material_slag ON x.MATERIAL_ID = stock_material_slag.MATERIAL_ID LEFT JOIN PUR_EPISODE_HDR ON STOCK_MATERIAL_EPI.ROW_ID_EPI = PUR_EPISODE_HDR.ROW_ID

Please sign in or create an account to participate in this conversation.