Results 1 to 4 of 4

Thread: Need Help in Select Query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Need Help in Select Query

    I have two tables named TBL_PAYMENT_TRN & TBL_PROFIT_PETROLEUM_TRN. I want to select all the records from the table TBL_PROFIT_PETROLEUM_TRN & the matching records from TBL_PAYMENT_TRN.

    In Figure 1 ,TBL_PAYMENT_TRN is dere.
    In Figure 2,TBL_PROFIT_PETROLEUM_TRN is dere.
    In Figure 3, See my Select Query Result

    Code:
    select TBL_PAYMENT_TRN.UTR_DD_NO,TBL_PROFIT_PETROLEUM_TRN.ACCOUNT_ID from TBL_PROFIT_PETROLEUM_TRN,TBL_PAYMENT_TRN where TBL_PROFIT_PETROLEUM_TRN.ACCOUNT_ID= TBL_PAYMENT_TRN.TRANSACTION_ID
    AND
    TBL_PAYMENT_TRN.TYPE_OF_PAYMENT_ID=3
    In TBL_PAYMENT_TRN one entry is made against ACCOUNT_ID of TBL_PROFIT_PETROLEUM_TRN. So above query selects dat.

    In TBL_PROFIT_PETROLEUM_TRN another entry is dere for ACCOUNT_ID - 378. I also wnat to select dat record & if there is no corresponding record in TBL_PAYMENT_TRN against dat ACCOUNT_ID,I want the null to come.

    How to do that!Help me out.

    I want the query in Oracle Plz Reply.

    I want the output to be like
    Code:
    UTR_DD_NO   ACCOUNT_ID
    utr1              379
    null               378
    Attached Images Attached Images    

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Need Help in Select Query

    Use a Left Join.

    Code:
    select TBL_PAYMENT_TRN.UTR_DD_NO,TBL_PROFIT_PETROLEUM_TRN.ACCOUNT_ID 
    From TBL_PROFIT_PETROLEUM_TRN
    LEFT JOIN TBL_PAYMENT_TRN On TBL_PROFIT_PETROLEUM_TRN.ACCOUNT_ID= TBL_PAYMENT_TRN.TRANSACTION_ID AND TBL_PAYMENT_TRN.TYPE_OF_PAYMENT_ID=3
    Which version of Oracle are you using? Older versions don't support the LEFT JOIN keywords. You will need to use *=, the old syntax of a left join.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Need Help in Select Query

    hi brucevde,thx very much!!!I want if there is no record only for column UTR_DD_NO,then in place of null 0 should be there!!!

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Need Help in Select Query

    Use either the Coalesce or NVL functions. They basically do the same thing.

    Select Coalesce(TBL_PAYMENT_TRN.UTR_DD_NO,0), ...
    Select NVL(TBL_PAYMENT_TRN.UTR_DD_NO,0), ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width