Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:53:32+00:00 2026-06-13T20:53:32+00:00

I have joined two tables using inner join. Here primary key of table TPREG

  • 0

I have joined two tables using inner join. Here primary key of table TPREG is co_id and pol_id

 SELECT (SELECT etbl_desc_txt
       FROM uding604.tedit e
       WHERE etbl_typ_id = 'PITCD'
       AND   co_id = 'CP'
       AND   etbl_valu_id = p.pol_ind_typ_cd) pol_ind_typ_cd,
       (SELECT etbl_desc_txt
        FROM uding604.tedit e
        WHERE etbl_typ_id = 'PAYT'
        AND   co_id = 'CP'
        AND   etbl_valu_id = p.POL_BILL_TYP_CD) POL_BILL_TYP_CD,
       POL_PAC_DRW_DY,
       (SELECT etbl_desc_txt
        FROM uding604.tedit e
        WHERE etbl_typ_id = 'PAYM'
        AND   co_id = 'CP'
        AND   etbl_valu_id = p.POL_BILL_MODE_CD) POL_BILL_MODE_CD,
       t.SOURCE_CD
FROM uding604.tpol p,
     uding604.TPREG t
WHERE p.co_id = t.co_id
AND   p.pol_id = t.pol_id
AND   p.co_id = 'CP'
AND   p.pol_id = '000000011'
AND   t.co_id = 'CP'
AND   t.pol_id = '000000011'

How to make this query more simple?

Please guide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:53:36+00:00Added an answer on June 13, 2026 at 8:53 pm

    You can transform the subqueryes to joins:.

    SELECT e1.etbl_desc_txt as pol_ind_typ_cd,
           e2.etbl_desc_txt as POL_BILL_TYP_CD,
           POL_PAC_DRW_DY,
           e3etbl_desc_txt as POL_BILL_MODE_CD,
           t.SOURCE_CD
    FROM uding604.tpol p,
         uding604.TPREG t,
         uding604.tedit e1,
         uding604.tedit e2,
         uding604.tedit e3
    WHERE p.co_id = t.co_id
    AND   p.pol_id = t.pol_id
    AND   p.co_id = 'CP'
    AND   p.pol_id = '000000011'
    AND   t.co_id = 'CP'
    AND   t.pol_id = '000000011'
    AND   e1.etbl_typ_id = 'PITCD'
    AND   e1.co_id = 'CP'
    AND   e1.etbl_valu_id = p.pol_ind_typ_cd
    AND   e2.etbl_typ_id = 'PAYT'
    AND   e2.co_id = 'CP'
    AND   e2.etbl_valu_id = p.POL_BILL_TYP_CD
    AND   e3.etbl_typ_id = 'PAYM'
    AND   e3.co_id = 'CP'
    AND   e3.etbl_valu_id = p.POL_BILL_MODE_CD
    

    The query is clearer on select clause but is fuzzy at Where clause.

    What we can do is to move on ANSI JOIN syntax:

    SELECT e1.etbl_desc_txt as pol_ind_typ_cd,
           e2.etbl_desc_txt as POL_BILL_TYP_CD,
           POL_PAC_DRW_DY,
           e3etbl_desc_txt as POL_BILL_MODE_CD,
           t.SOURCE_CD
    FROM uding604.tpol p 
    JOIN uding604.TPREG t on (p.co_id = t.co_id AND p.pol_id = t.pol_id)
    JOIN uding604.tedit e1 on (e1.etbl_valu_id = p.pol_ind_typ_cd and e1.co_id = p.co_id)
    JOIN uding604.tedit e2 on (e2.etbl_valu_id = p.POL_BILL_TYP_CD and e2.co_id = p.co_id)
    JOIN uding604.tedit e3 on (e3.etbl_valu_id = p.POL_BILL_MODE_CD and e3.co_id = p.co_id)
    WHERE p.co_id = 'CP'
    AND   p.pol_id = '000000011'
    AND   t.co_id = 'CP'
    AND   t.pol_id = '000000011'
    AND   e1.etbl_typ_id = 'PITCD'
    AND   e2.etbl_typ_id = 'PAYT'
    AND   e3.etbl_typ_id = 'PAYM'
    

    Now is clearer what you want.

    Note1. You may try to remove

    AND   t.co_id = 'CP'
    AND   t.pol_id = '000000011'
    

    because is not logic necessarly.

    Note2. You must test if these queryes return the same as your query.

    Note3. You should allways use ANSI JOIN syntax, will help you when you not expect it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables (Table A, Table B) joined with a join table (TableAB)
I have two tables that should be joined together by a foreign key relationship,
I have two tables that get joined regularly. Table One is about 1 Million
I am building a photo uploading website and I have joined two tables together
I have following tables in MySQL.(I am using php/mysql) CREATE TABLE `hw_subjects` ( `id`
In MySQL I know its possible to select from two tables that have been
I am trying to join two tables together using C# linq to entities. One
I have two tables TABLE_A and TABLE_B having the joined column as the employee
ASP.NET 3.5 C# I am joining two tables using Linq. Table names are MapAssets
I have two tables. First table have columns: price, code_one Second table has: code_one,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.