1

I have query that is and I have executed the query..

first is the TXN_HEADER table .

select * from TXN_HEADER where txhd_receipt_id = 'receipt_id_val' and till_short_desc = 'till_no_val'

from the above TXN_HEADER table we get the transaction_no value ( e.g. txhd_txn_nr) which is used to find the transactional details in TXN_DETAIL table.

select * from TXN_DETAIL where txhd_txn_nr = 'transaction_no_val' and till_short_desc = 'till_no_val

My query is that I am writing these queries seprately can you guys please advise by which I can combine them into single query by any means , I means through subquery , through joins . please advise.

4

3 回答 3

1

加入版:

select * 
  from TXN_HEADER 
 inner join TXN_DETAIL 
    on TXN_HEADER.txhd_txn_nr = TXN_DETAIL.txhd_txn_nr
 where TXN_HEADER.txhd_receipt_id = 'receipt_id_val' 
   and TXN_HEADER.till_short_desc = 'till_no_val'
   and TXN_DETAIL.till_short_desc = 'till_no_val'
于 2012-07-12T08:56:33.337 回答
0

如果列 [txhd_txn_nr] 可以关联这两个表,您可以尝试使用此查询:

select * from TXN_DETAIL where txhd_txn_nr in (select transaction_no_val from TXN_HEADER where txhd_receipt_id = 'receipt_id_val' and till_short_desc = 'till_no_val') and till_short_desc = 'till_no_val
于 2012-07-12T08:57:48.370 回答
0

你应该有一个身份证才能加入

select * from TXN_HEADER H
join TXN_DETAIL D
on H.<id>=D.<id>
where  H.txhd_receipt_id = 'receipt_id_val' and H.till_short_desc = 'till_no_val'
and D.txhd_txn_nr = 'transaction_no_val' and D.till_short_desc = 'till_no_val'
于 2012-07-12T08:58:14.160 回答