select bd_glorgbook.glorgbookcode,gl_voucher.year,gl_voucher.period,gl_voucher.no
from gl_voucher,bd_glorgbook
where gl_voucher.pk_glorgbook=bd_glorgbook.pk_glorgbook
AND gl_voucher.pk_voucher in
( select pk_voucher from gl_detail,bd_accsubj
where gl_detail.pk_accsubj=bd_accsubj.pk_accsubj
and bd_accsubj.endflag='N'
)
order by 1
select* from gl_detail where pk_accsubj in (select pk_accsubj from bd_accsubj where bd_accsubj .Endflag='N')