Join operations

Several textbooks (incl Oracle) claim that:
"There are some rules that one should remember for table joins: Data from two or more tables can be joined, if the same column (under the same or a different name) appears in both tables, and the column is the primary key (or part of that key) in one of the tables".
I think this statement can be somewhat misleading since it seems to describe the typical primary-key/foreign-key equijoin operation rather than a common characteristic of all join operations, including non-equijoins.
Of course, nothing prevents you from joining tables on whichever columns you choose, but the result may be meaningless. However, if you consider a non-equijoin operation, which can be useful on some occasions, none of the two rules need be fulfilled and the result will still make sense. The same column need not be present in both columns and need not be the primary key in the tables.
Anyone else find these "rules" somewhat misleading ?
br,
Sven

Assuming that by "rules" here, the text is indicating common practices or rules of thumb, rather than hard algorithms, I think this makes perfect sense.
The "same column" rule appears to require that the data in two different columns represents the same thing. You could join employee numbers to employee salaries, but the result would be nonsense.
The "primary key" rule appears to assume a properly normalized schema. If all your tables are normalized, the only way that a join would make sense would be if the join column was a primary key on one of the tables. If employee name is not a primary key, then you would expect employee name to exist in one and only one table, hence, there would be no other column it would make sense to join with.
Now, reality often gives us rather less normalized schema designs, which introduces most of the cases I can think of that violate these rules of thumb.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Non-ANSI Outer Join Operator Issue (reposted due to text issues)

    I am currently using Designer 11.5.0.0. Itu2019s XI Rel 2, but Iu2019m not sure what service pack. I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
    Failed to retrieve date from the database. Details: 42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
    Here is my ODBC DSN configuration:
    Microsoft SQL Server ODBC Driver Version 03.85.1132
    Data Source Name: FlexOPS
    Data Source Description:
    Server: dalsvrw031
    Database: (Default)
    Language: (Default)
    Translate Character
    Data: Yes
    Log Long Running Queries: No
    Log Driver Statistics: No
    Use Integrated Security: No
    Use Regional Settings: No
    Prepared Statements Option: Drop temporary procedures on disconnect
    Use Failover Server: No
    Use ANSI Quoted Identifiers: Yes
    Use ANSI Null, Paddings and Warnings: Yes
    Data Encryption: No
    Okay, so I understand what the issue is. It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D. So all the outer joins I have created in each of my universe are using the old *= as the join operator. And apparently, the ODBC driver I am using is not very happy with that.
    As I understand it from what Iu2019ve read on other sites, I have the following options:
    1) Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
    2) Find a different driver or connectivity method that will support non-ANSI joins.
    3) Set my database back to SQL 2000 compatibility.
    Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing. Option 2 is only a band-aid fix at best. Option 3 really isnu2019t an option for us.

    So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins. Do I need to update Designer with a service pack? Is there a script out there that will automatically do this in each of the universes? I would appreciate any suggestions or guidance on this.
    Thanks,
    Lee

  • Non-ANSI Outer Join Operator Issue

    I am currently using Designer 11.5.0.0.  Itu2019s XI Rel 2, but Iu2019m not sure what service pack.  I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
    Failed to retrieve date from the database.
    Details:  42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D).  To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel.  It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN).  In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
    Here is my ODBC DSN configuration:
    Microsoft SQL Server ODBC Driver Version 03.85.1132
    Data Source Name: FlexOPS
    Data Source Description:
    Server: dalsvrw031
    Database: (Default)
    Language: (Default)
    Translate Character Data: Yes
    Log Long Running Queries: No
    Log Driver Statistics: No
    Use Integrated Security: No
    Use Regional Settings: No
    Prepared Statements Option: Drop temporary procedures on disconnect
    Use Failover Server: No
    Use ANSI Quoted Identifiers: Yes
    Use ANSI Null, Paddings and Warnings: Yes
    Data Encryption: No
    Okay, so I understand what the issue is.  It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D.  So all the outer joins I have created in each of my universe are using the old *= as the join operator.  And apparently, the ODBC driver I am using is not very happy with that.
    As I understand it from what Iu2019ve read on other sites, I have the following options:
    1)   Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
    2)   Find a different driver or connectivity method that will support non-ANSI joins.
    3)   Set my database back to SQL 2000 compatibility.
    Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing.  Option 2 is only a band-aid fix at best.  Option 3 really isnu2019t an option for us.
    So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins.  Do I need to update Designer with a service pack?  Is there a script out there that will automatically do this in each of the universes?
    I would appreciate any suggestions or guidance on this.
    Thanks,
    Lee
    Edited by: Lee Vance on Jul 6, 2009 10:02 PM

    Hi,
    try the following:
    open your universe in the Universe designer, go to File->Parameter, select the Parameter tab and change the value of the ANSI92 parameter from No to Yes.
    Regards,
    Stratos

  • Mapping with joiner operator cannot be validated/deployed - why?

    hi guys,
    i want to join two oracle tables with a flatfile in a mapping and output it into a new table (staging_table).
    so i created a new mapping, imported the sources and drag-drop the joiner operator. i connected the the sources with the joiner and set the how to join in the operator properties. finally i connected the join-output with a new table.
    problem: validating this mapping did not work!! the validating report did not even put an error or warning, it just says "wasnt validated".
    anybody any idea ??
    greetings
    s8472

    Hello,
    I\m not sure you could combine within one mapping flat file and tables as a source. The thing is – if you are creating a flat file–to-table mapping OWB will generate control file for Oracle Loader as a result.
    I’d advice you to cover your flat file with an external table, and this external table could take place of the flat file in your mapping. Everything will work fine.
    Sergey

  • Outer Join problems - "ORA-30563 outer join operator (+) not allowed in select-list"

    Products: Discoverer 4.1.33.0.2
    (Admin and User/Plus)
    8i EE 8.1.7 (Discoverer server)
    8i EE 8.1.5 ('source data' server)
    Background assumptions: (1) If a column from an "outer-joined" table is compared to a constant, the outer join operator must be applied to that column in order for the outer join to work. (2) A 'Condition' specified in Discoverer User/Plus manifests as a comparison to a constant.
    I created a join in Admin between two folders, selected 'outer join on detail' option. In User/Plus, created worksheet containing columns from the joined folders. When no Conditions are NOT specified, results seem ok. However, when Condition IS added, worksheet encounters "ORA-30563 outer join operator (+) not allowed in select-list" and returns blank sheet.
    To workaround, created Custom folder with outer join in place. Didn't work either with Conditions specified. No error, but I think that because Discoverer did not 'outer join' the Condition column, the outer join was ignored.
    Any insights, ideas, or workarounds are much appreciated.
    -Jim

    If you build a query that uses an outer join then any items from the potentially deficient side of the join will have (+) appended to them everywhere in the sql. Up until 8.1.7 this was OK in the select list as it was just treated as noise and ignored - However this now fails with ORA-30563:
    outer join operator (+) not allowed in select-list...
    In 4.1.33.1.6 you get the error 'ORA-30563 outer join operator(+) not allowed in select list'.
    In 4.1.36.1.10 the query runs OK.. Your work around I would guess would be to create a custom folder as you suggested.

  • How to achieve outer join operator(+) in HQL?

    Dear all,
    The two tables employee and customer have not explicate association (by FK and PK). In Oracle SQL, we can use the operator (+) as follows for an outer join. For example,
    SELECT * FROM  employee, customer           where employee.name = customer.name(+)
    However, HQL does not support this outer join operator. How can we translate the above SQL select to HQL?
    Regards.
    Pengyou

    shashi_rajak wrote:
    Already posted in [ hibernate forum|https://forum.hibernate.org/viewtopic.php?f=1&t=997869] . This does not have to do with java.
    Yes, but I did not get any solution.
    Hibernate has something to do with java. You can not say for example java has nothing to do with Internet or Internet has nothing to do with Computer. Anyhow, thanks for your reply.

  • ORA-01719: outer join operator (+) not allowed in operand of OR or IN

    I am getting the following Error when I tried to execute my Query.
    Error : ORA-01719: outer join operator (+) not allowed in operand of OR or IN
    select unique t.estblmt_src_typ_id as estblmt_src_typ_id,
    t.name as name from estblmt_src_typ t, src_estblmt_unknown_data u, estblmt_src eSrc, estblmt e,
    additional_addr aa, country c, src_country_state_region scsr
    where
    (t.estblmt_src_typ_id=u.estblmt_src_typ_id and
    e.state_region_id=scsr.state_region_id and
    upper(scsr.code1)='UNKNOWN' and
    u.processed_ind = 'N' and
    eSrc.Estblmt_Alt_Id = u.estblmt_alt_id and
    u.estblmt_src_typ_id = eSrc.estblmt_src_typ_id and
    eSrc.Estblmt_Id = e.estblmt_id and
    e.country_id = c.country_id and
    u.estblmt_element = 'State Region' and
    scsr.estblmt_src_typ_id = u.estblmt_src_typ_id and
    aa.estblmt_id(+)=e.estblmt_id and
    e.end_dt is null) or
    (t.estblmt_src_typ_id=u.estblmt_src_typ_id and
    aa.state_region_id=scsr.state_region_id and
    upper(scsr.code1)='UNKNOWN' and u.processed_ind = 'N' and
    eSrc.Estblmt_Alt_Id = u.estblmt_alt_id and
    u.estblmt_src_typ_id = eSrc.estblmt_src_typ_id and
    eSrc.Estblmt_Id = aa.estblmt_id and aa.country_id = c.country_id and (u.estblmt_element = 'Additional State Code' or u.estblmt_element = 'Additional State Province') and scsr.estblmt_src_typ_id = u.estblmt_src_typ_id
    and aa.estblmt_id=e.estblmt_id and e.end_dt is null) order by t.name

    First, is this query being executed within Apex or at the SQL prompt or in SQL Workshop, or something else? Some context of where it's being executed may help.
    Next, that's a query from hell. How about rewrting it to use ANSI join syntax instead, so it'a bit more readable?
    A quick example for part of it would be:
    FROM (additional_addr aa LEFT OUTER JOIN estblmt e ON aa.estblmt_id = e.estblmt_id )
    etc.
    Just add additional parenthesis for each additional table join, similar to:
    FROM ((additional_addr aa LEFT OUTER JOIN estblmt e ON aa.estblmt_id = e.estblmt_id )
    LEFT OUTER JOIN src_country_state_region scsr ON aa.state_region_id = scsr.state_region_id )
    In the long run it will make the query a bit more legible, so your where clause only lists the query conditions, not the join conditions. Then it becomes easier to quickly glance at it and see where potential problems may be.
    Bill Ferguson

  • NOT IN in OWB JOIN OPERATOR

    Select name from table_a where name not in (select related_name from table_b)
              ---neither of the attributes are in a key
    Select name from table_a where name != any (select related_name from table_b)
              -- this query makes Cartesian resultset
    What's wrong over here
    I just want to use the JOIN operator to implement this query (Select name from table_a where name not in (select related_name from table_b))

    Hello, I think you mean
    Select name from table_a where name != all (select related_name from table_b)
    which is equivalent to NOT IN.
    The operator " != any " yields always true if there is >1 element selected from table_b.
    You can join table_a and table_b and write the following join condition
    table_a.name = table_b.name (+)
    and table_b.name is null
    Hope this helps, Antonio
    Ops, I copied your statement without replacing any with all ...
    Message was edited by:
    antonio.delogu

  • Can we perform Join operation using SQLCall with Datatabae Query

    Hi,
    I am working on Toplink SQLCall query. I am performing join operation but, it is giving error.
    so please, any can tell me . we can perform join operation using SQLCall with Database Query
    Thanking You.

    You can use joining with SQLCall queries in TopLink, provided your SQL returns all of the required fields.
    What is the query you are executing and what error are you getting?

  • Does Toplink support PL/SQL storedProcedure (cursor + join operation)

    Hi,
    Context:- There are two table with relation (Emp, Dept). I am getting data from both table by using Join opeation.
    I am working on Toplink storedProcedureCall and want to get PL/SQL Cursor + join operation
    for example:- select d.dname,e.ename,e.sal from emp e, dept d where e.deptno=d.deptno;
    it's working fine but, when I am dragging DataControl on Form it's only showing EMP attribute but, I need to both EMP,DEPT attribute so that I can display ADF readonly Table control.
    please, help me out. Thanking You.
    regards,
    sufi

    Hello Adilz,
    You seem to have posted a number of times trying to get cursors to work. Cursors do work, and in this case it looks like your stored proc is not working because the procedure you are calling does not accept any output variables - hence the error stating the wrong number of arguments.
    Try defining read_emp and ename in your stored procedure definition in the database.
    Best Regards,
    Chris

  • Mappings between table operator and joiner operator

    HI all,
    I am new to owb. I am trying to create a mapping in the OWB Mapping Editor where the scenario looks like :
    table1 operator ---------> joiner file operator
    i am looking at earlier mappings' sql code and found that there is a where clause condition that governing the above such scenario such as:
    where table1.column value = "something" then load into joiner file operator.
    But in the mapping editor, i cannot find any way to add this condition by clicking on the column name of table1. Please help.
    thank you.

    Hi
    A joiner will make one output from 2 or more inputs. A joiner has a join condition which if you select the operator (not a group or an attribute with operator) the property inspector will have a join condition for detailing the 'where' clause.
    If you want to filter a single input then use a filter operator. Again like condition the filter operator has a filter condition which if you select the operator (not a group or an attribute with operator) the property inspector will have a filter condition for detailing the 'where' clause.
    Cheers
    David

  • Max sal using set or join operations

    Hi,
    how to write a sql query to retrieve max sal of an emp table without using max()function.
    and using only set operations or join conditions..
    cheers..

    You can use an analytic function for this. You can either use ROW_NUMBER or RANK or DENSE_RANK
    with my_emp
    as
    select empno, ename, sal, rank() over(order by sal desc) rk
      from emp
    select empno, ename, sal
      from my_emp
    where rk = 1

  • Doubt Regarding LEFT JOIN Operation

    Hello,
    With the Old syntax in place it is easier for find that which join is performed on which table ...
    But with the new syntax ..m getting bit confused when INNER & LEFT JOINS used together ...
    Below is the FROM clause ...please explain .. how this JOIN is gonna take place ..& which table is Left joined with whom...
    FROM VW_TRANS_MANAGER_SALES ref_1
    LEFT OUTER JOIN VW_AGREE_ASSIGN_TAG_DTLS ass
    ON Trim(ass.agreement_id) = trim(ref_1.AGREEMENT_ID)
    LEFT OUTER JOIN VW_CURENT_RATING_DTLS CURR
    ON (ref_1.company_code =curr.COMPANYCODE)
    LEFT OUTER JOIN VW_PREV_RATING_DETAILS PREV
    ON (ref_1.company_code =prev.COMPANYCODE)
    LEFT OUTER JOIN CRMADMIN.CO_MA_COMPANY_CONTACTS cont
    ON (ref_1.CLIENT_CONTACT_ID= cont.CONTACT_ID)
    LEFT OUTER JOIN CRMADMIN.COR_CRM_MST_CITY city
    ON (city.City_id= cont.City_id))
    ---------------------------------------------------------------------------------------------------------------------------------------

    Hi,
    Aijaz Mallick wrote:
    Yeah .. but was a bit Confusing as u used 2 columns in each table....
    Doesn't it depends on the joining condition we use ... lets Say ..if i use an INNER join after 2 LEFT join ... & m doing an that inner join with the first SOURCE table .... then will it perform a join on the resultset on the previous Joins...???Sorry, I'm not sure what you're asking.
    Please post a specific example of a join that you don't understand, or some results that you don't know how to get.
    Use commonly available tables (like those in the scott or hr schemas) or post your own CREATE TABLE and INSERT statements.
    Using ANSI syntax, the results are as if the joins were done in the order they appear in the FROM clause (even though the optimizer may not actually do them in that order).
    For example, in the querry below, the inner-join between emp and salgrade is done first, then the outer join with dept is done to that result set.
    SELECT     d.dname
    ,     e.ename
    ,     g.losal
    FROM          scott.emp     e
    JOIN          scott.salgrade     g     ON     e.sal     BETWEEN     g.losal
                                       AND     g.hisal
    RIGHT OUTER JOIN  scott.dept     d     ON     e.deptno     = d.deptno
    ;Output:
    DNAME          ENAME           LOSAL
    ACCOUNTING     CLARK            2001
    ACCOUNTING     MILLER           1201
    ACCOUNTING     KING             3001
    RESEARCH       FORD             2001
    RESEARCH       SCOTT            2001
    RESEARCH       JONES            2001
    RESEARCH       ADAMS             700
    RESEARCH       SMITH             700
    SALES          BLAKE            2001
    SALES          ALLEN            1401
    SALES          MARTIN           1201
    SALES          WARD             1201
    SALES          JAMES             700
    SALES          TURNER           1401
    OPERATIONSNotice that the OPERATIONS department, which has no matches in the other tables, is still included because of the outer join.
    If you want to have the joins done in a different order, you can explicitly join some table first, either in a sub-query or just by grouping joins within parentheses in the same FROM clause, as in the query below (which produces the same results as the query above):
    SELECT     d.dname
    ,     e.ename
    ,     g.losal
    FROM          scott.dept     d
    LEFT OUTER JOIN     (     -- Join the following tables first:
                   scott.emp     e
              JOIN     scott.salgrade     g     ON     e.sal     BETWEEN     g.losal
                                            AND     g.hisal
              )     ON     d.deptno     = e.deptno
    ;

  • Need Help in creating a subquery using JOIN operation

    Hi,
    I am new to SQL and trying to write a query. Please help me in this.
    The Database Schema looks like this:
    The database scheme consists of four tables:
    Product(maker, model, type)
    PC(code, model, speed, ram, hd, cd, price)
    Laptop(code, model, speed, ram, hd, screen, price)
    Printer(code, model, color, type, price)
    The table "Product" includes information about the maker, model number, and type ('PC', 'Laptop', or 'Printer'). It is assumed that model numbers in the Product table are unique for all the makers and product types. Each PC uniquely specifying by a code in the table "PC" is characterized by model (foreign key referencing to Product table), speed (of the processor in MHz), total amount of RAM - ram (in Mb), hard disk drive capacity - hd (in Gb), CD ROM speed - cd (for example, '4x'), and the price. The table "Laptop" is similar to that one of PCs except for the CD ROM speed, which is replaced by the screen size - screen (in inches). For each printer in the table "Printer" it is told whether the printer is color or not (color attribute is 'y' for color printers; otherwise it is 'n'), printer type (laser, jet, or matrix), and the price.
    Alternatively you can refer here for the schema (Computer Firm)
    http://www.sql-ex.ru/help/select13.php#db_1
    Now my query is :
    Find the makers of the cheapest color printers.
    Result set: maker, price.
    and I have written the query as:
    SELECT prod.maker, prin.* FROM (SELECT MIN(price) AS price FROM printer WHERE color = 'y') AS prin INNER JOIN (SELECT maker, model FROM product) AS prod ON prin.model = prod.model
    Which is giving the error "Invalid column name 'model'.". Please help!
    Thanks!
    Faaz

    Hello,
    Your query does not work because your subquery prin does not return a column named model.
    Analytical functions like Vivek L suggests are the best way to do this, but this one is a correction of your query and should work too (not tested, unfortunately).
    SELECT prod.maker, prin2.*
    FROM  (SELECT MIN(price) AS min_price FROM printer WHERE color = 'y') AS prin
    INNER JOIN (SELECT model, price FROM printer WHERE color='y' ) AS prin2  ON prin.min_price = prin2.price
    INNER JOIN (SELECT maker, model FROM product) AS prod ON prin2.model = prod.model;Regards,
    Sylvie

  • How to implement Union and Join operations in OBIEE

    Hi all,
    Am new to OBIEE. Can some one tell me the right place to create Union and Joins in OBIEE....
    Do i need to create Union or Join in Oracle(DB level) or do i have the option of creating Union/Join in Physical layer or BMM layer. I tried creating a union in Physical layer,but when i check the the data in presentation layer,i see only data from 1st table.
    Thanks you
    Praveen

    Union - in the physical layer when creating new physical table/table type select:
    Example:
    select 1 as id from dual union all
    select 2 as id from dual
    Joins - You create them in the physical layer (FK, complex) and in the BMM (complex).
    You don't need to create joins in the database.
    Regards
    Goran
    http://108obiee.blogspot.com

Maybe you are looking for

  • N95 Help Application not working!

    i have trouble with my N95 Help Application, it dose'nt work, i can only run it, and see the main list, i did'nt complain before cause i hardly used it! but now, when i use help from other software, i get the same error " message Memory Full. Close s

  • Homesharing Import button grayed out.

    I recently bought a MacBook Air and I have an iMac. Both have Homesharing turned on and I can see my iMac's iTunes library on my Air. But the Import button is grayed out and won't let me click on it when I try to import playlists to my Mac Air. Can a

  • How to transfer number to Excel column letter

    I want to write a table into Excel file with fomula "=AVERAGE(G18:G64)", how to transfer table column nunber into excel column letter? for example, from table column 7, how to know 7 means G in excel? thanks!

  • MDM Material...

    Hi Folks, I am new to MDM so went through the bible of Netweaver i.e SDN. and found that there is pdf document by the name : SAP NetWeaver MDM Overview  But could not download as the file seems to be corrupted....Can anybody help me in this context..

  • Creating work flow

    Hi  all, i am new to Work flow, can any body tell me how can i trigger the work flow from my abap program, and how can i send the required details from the program to W/F ? kumar