SELECT a.*,po_id FROM ( select store_receive_no,concat(cm.sr_prefix,"/",bm.branch_name,"/",ay.string_label,"/",ssh.store_receive_no ) inwardseqno, ssh.gate_entry_no, gserh.in_date, case when length(ifnull(gserh.po_no,' '))=0 then 'WITHOUTPO' else 'WITHPO' end psource,'GRN' rectype,ssh.remarks, ssh.challan_no ,ssh.challan_date ,ssh.store_receive_dt ,s.supp_id ,ssh.company_id , ssh.branch_id ,ssh.project_id ,ssh.internal_note ,gserh.inspec_check ,ssh.sr_good_recept_status ,ssh.tax_type , ssh.store_print_no ,ssh.store_receipt_no , case when ssh.tax_type=1 then 'IGST' when ssh.tax_type=2 then 'CGST & SGST' else 'NO TAX' end taxname ,gserh.po_no from scm_sr_hdr ssh ,company_master cm ,academic_years ay ,branch_master bm ,gate_store_entry_reg_hdr gserh ,suppliermaster s where ssh.company_id =cm.comp_id and ssh.ac_year =ay.year and ssh.company_id =ay.company_id and ssh.branch_id =bm.branch_id and ssh.gate_entry_no =gserh.hdr_id and ssh.supp_code =s.supp_code and ( s.status=60 or s.status=90) union all SELECT store_receive_no,concat(cm.sr_prefix,"/",bm.branch_name,"/",ay.string_label,"/",ssh.store_receive_no ) inwardseqno, 'NULL' gate_entry_no, store_receive_dt in_date,'WITHOUTPO' psource,'GRN' rectype ,remarks,challan_no,challan_date,ssh.store_receive_dt, 'NULL' supp_id, ssh.company_id,ssh.branch_id,project_id,'OP.Stock' internal_note,'Y' inspec_check,sr_good_recept_status ,4 tax_type, store_print_no,store_receipt_no,'NO TAX','NULL' po_no FROM scm_sr_hdr ssh ,company_master cm ,academic_years ay ,branch_master bm where ssh.company_id =cm.comp_id and ssh.ac_year =ay.year and ssh.company_id =ay.company_id and ssh.branch_id =bm.branch_id AND store_receive_no IN (3391,3595,7407,9178) ) a LEFT JOIN tbl_proc_po tpp on a.po_no=tpp.po_sequence_no ORDER BY store_receive_no DESC