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 8709997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:30:39+00:00 2026-06-13T04:30:39+00:00

I am re-writing a query that was generated by Business Objects and uses old-fashioned

  • 0

I am re-writing a query that was generated by Business Objects and uses “old-fashioned” implicit join syntax. The code joins a table to itself in one part and also has a “global” where clause. For example:

select   a.col1
       , b.col2
from     MYDB.TABLE a, MYDB.TABLE b
where    a.something=b.something_else
     and MYDB.TABLE.source='A'

Above is a made up illustration of the question. The actual query is very long, joining about ten tables.

My question: as written above, does the “extra” where condition apply to both instances of the same table? I think yes, but I’ve never seen code like this before. I’m using Teradata but I think this is a general SQL question.

UPDATE: Perhaps my attempt to narrow the question wasn’t accurate. Here is the complete query I’m trying to modify:

SELECT
  abs_contrct_prof.contrct_nbr_txt,
  gbs_org_LVL1.bus_pln_sgmnt_cd,
  abs_gnrc_lst_of_val_LVL1.wirls_val_1_txt
FROM
  EDWABSUSERVIEWS.abs_contrct  abs_contrct_prof,
  EDWABSUSERVIEWS.gbs_org  gbs_org_LVL1,
  EDWABSUSERVIEWS.abs_gnrc_lst_of_val  abs_gnrc_lst_of_val_LVL1,
  EDWABSUSERVIEWS.abs_contrct,
  EDWABSUSERVIEWS.gbs_sls_actv_blng_org_rltd,
  EDWABSUSERVIEWS.gbs_sls_actv_org_rltd
WHERE
  ( abs_contrct_prof.type_cd = 'PROFILE'  )
  AND  ( EDWABSUSERVIEWS.abs_contrct.type_cd = 'AGREEMENT'  )
  AND  ( abs_contrct_prof.prnt_contrct_id=EDWABSUSERVIEWS.abs_contrct.contrct_id  )
  AND  ( abs_contrct_prof.org_id=EDWABSUSERVIEWS.gbs_sls_actv_org_rltd.org_id  )
  AND  ( EDWABSUSERVIEWS.gbs_sls_actv_org_rltd.gbs_lvl_3_org_id=EDWABSUSERVIEWS.gbs_sls_actv_blng_org_rltd.gbs_lvl_3_org_id  )
  AND  ( EDWABSUSERVIEWS.gbs_sls_actv_blng_org_rltd.gbs_lvl_1_org_id = gbs_org_LVL1.org_id  )
  AND  ( gbs_org_LVL1.bus_pln_sgmnt_cd=abs_gnrc_lst_of_val_LVL1.nm_txt and abs_gnrc_lst_of_val_LVL1.actv_ind = 'Y' and abs_gnrc_lst_of_val_LVL1.type_cd ='ABS_MOBILITY_SEGMENT'  )
  AND  
  abs_contrct_prof.contrct_nbr_txt  IN  @variable('FAN')
  AND  ( EDWABSUSERVIEWS.abs_contrct.sts_cd = 'Active'  )
  AND  ( EDWABSUSERVIEWS.abs_contrct.type_cd='AGREEMENT'  )

Note the table EDWABSUSERVIEWS.abs_contrct is referenced twice in the FROM clause, one time using an alias and once without. And yes, this query works as written, but I want to re-write it to use explict join syntax (as someone commented).

I ran an EXPLAIN on the query and it appears that the “extra” where conditions (for ‘Active’ and ‘AGREEMENT’) are in fact applied to both instances of the table separately.

  • 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-13T04:30:41+00:00Added an answer on June 13, 2026 at 4:30 am

    If your TRANSACTION MODE is TERADATA the optimizer will product join the fully qualified table reference in the WHERE clause against the spool file containing the INNER JOIN results. I have not been able to test this yet with TRANSACTION MODE set to ANSI.

    Example

    CREATE VOLATILE TABLE Test1
        (
            Col1 SMALLINT NOT NULL,
            col2 VARCHAR(10) NOT NULL
        )
        PRIMARY INDEX (Col1)
        ON COMMIT PRESERVE ROWS;
    
    CREATE VOLATILE TABLE Test2
        (
            Col1 SMALLINT NOT NULL,
            col2 VARCHAR(10) NOT NULL
        )
        PRIMARY INDEX (Col1)
        ON COMMIT PRESERVE ROWS;
    
    SELECT A.Col1
         , B.Col2
         , Test1.Col1
      FROM Test1 A
         , Test2 B
     WHERE A.Col1 = B.Col1
       AND Test1.Col1 = 1;
    

    Explain – Teradata Mode

      1) First, we do an all-AMPs JOIN step from USER.B by way of a RowHash
         match scan with no residual conditions, which is joined to USER.A
         by way of a RowHash match scan with no residual conditions. 
         USER.B and USER.A are joined using a merge join, with a join
         condition of ("USER.A.Col1 = USER.B.Col1").  The result goes into
         Spool 2 (one-amp), which is redistributed by the hash code of (9)
         to all AMPs.  The size of Spool 2 is estimated with low confidence
         to be 1 row (15 bytes).  The estimated time for this step is 0.02
         seconds. 
      2) Next, we do a single-AMP JOIN step from Spool 2 (Last Use) by way
         of an all-rows scan, which is joined to USER.Test1 by way of the
         primary index "USER.Test1.Col1 = 1" with no residual conditions. 
         Spool 2 and USER.Test1 are joined using a product join, with a
         join condition of ("(1=1)").  The result goes into Spool 1
         (all_amps), which is built locally on that AMP.  The size of Spool
         1 is estimated with low confidence to be 1 row (22 bytes).  The
         estimated time for this step is 0.01 seconds. 
      3) Finally, we send out an END TRANSACTION step to all AMPs involved
         in processing the request.
      -> The contents of Spool 1 are sent back to the user as the result of
         statement 1.  The total estimated time is 0.03 seconds. 
    

    UPDATE

    INSERT INTO Test1 VALUES (1,'C');
    INSERT INTO Test1 VALUES (2,'D');
    INSERT INTO Test2 VALUES (1, 'C1');
    INSERT INTO Test2 Values (2, 'D2');
    

    Results

    Col1  Col2  Test1.Col1
    ----++----++----------
    1     C1    1
    2     D2    1
    

    The filter condition was not applied to the tables in the FROM clause.

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

Sidebar

Related Questions

I'm writing a query that inserts customer data into a MSSQL database. Very basic.
I am having trouble writing query so that I can query the content of
I was successful in writing the query that lists salesmen that did sell to
How would one go about writing a query that selects items 2000-2010 out of
I'm writing a PHP script that builds an SQL query by concatenating the string
I am writing a class that contains an array of other objects that it
I need help writing a T-SQL query that will generate 52 rows of data
I am writing a query for a very specific report that contains a variable
I'm writing a library that wraps libpq in C. When I execute a query
I'm writing a application where the user can write json-code and store that json

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.