Join the tables of towing on the overlap of the keywords.

I must join two large tables and have the situation like this:

TABLE_1TABLE_2
Ibis<>-Ibis Sydney Airport
the Ibis budget<>-Ibis budget Enfield
Ibis Styles<>-Hotel Port Hedland

And avoid the situation like this:

TABLE_1TABLE_2
IbisNO.Ibis budget Enfield
IbisNO.Hotel Port Hedland

Is it possible using SQL/PLSQL?

The solution is strongly dependent on the structur of your data.

A simpe approach can be:

with t1 as)
Select'ibis all of the double union
the select 'ibis' Union budget double all the
Select'ibis Styles of double
)
t2 as)
Select 'ibis Sydney Airport' t of all the double union
' select'ibis budget Enfield "of all the double union
' select'ibis Styles Port Hedland "double
)

Select t, s of)
Select
s
t
, row_number() over (partition by order of t by length (regexp_replace (t, ' ^': s l)))
from t1
t2
where
length (regexp_replace (t, ' ^': s))< length="">
)
where
l = 1
order of s

T, S

"ibis Sydney Airport", "ibis".

"ibis Styles Port Hedland", "ibis Styles.

"ibis budget Enfield", "ibis budget."

If regexp will not run, you can relax the requirement that the match should start at the beginning and replace rege_replace by just replace.

Tags: Database

Similar Questions

  • How to join two tables if you transpose the rows, columns and rows in one of the table

    Hi guys,.

    can someone help me please in the write request

    I have two tables

    Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)

    So instead of display 4 rows, I used max(case...) to convert rows to columns

    now how to reach it with another table

    Requirement:

    Database: 11.2.0.2.0

    create the table AGENT_PHONE

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    Phone_Number VARCHAR2 (16) not null,

    phone_type_code VARCHAR2 (10) not null

    )

    CREATE TABLEAGENTS

    (

    agent_id NUMBER (20) not null,

    agent_type_code VARCHAR2 (10) not null,

    agent_type_prefix VARCHAR2 (10) not null,

    NAME VARCHAR2 (40) NOT NULL

    )

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');

    INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)

    VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');

    INSERT INTO VALUES AGENTS

    (29709, ARE ', 'OFFICE', 'FLY');

    INSERT INTO VALUES AGENTS

    (1234, ARE ', 'OFFICE', 'MIKE');

    SELECT * FROM AGENT_PHONES

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE

    ---------------------------------------------------------------------------------------------

    29709REOFFICE4805551436CELL
    29709REOFFICE1111111111PHONE
    29709REOFFICE2223334444OFF
    29709REOFFICE5556667788

    FAX

    SELECT * AGENTS

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIX

    NAME

    29709REOFFICEROB
    1234REOFFICE

    MIKE

    This is so the data we have in both table

    Now, I transposed rows to columns in the table of agent phones so I used the following query

    SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.

    MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.

    MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE

    AGENT_PHONE AP

    WHERE AP. AGENT_ID = 29709

    GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLOFFFAXPHONE
    129709REOFFICE4805551436222333444455566677881111111111

    My question is how this to join the agents table so that my output should be like this...

    I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXCELLPHONEOFFFAX

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    29709REOFFICEROB29709REOFFICE4805551436111111111122233344445556667788
    1234REOFFICEMIKE

    Currently, I run this query and I get the output as below

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXNAMEAGENT_IDAGENT_TYPE_CODEAGENT_TYPE_PREFIXPHONE_NUMBERPHONE_TYPE_CODE
    129709REOFFICEROB29709REOFFICE4805551436CELL
    229709REOFFICEROB29709REOFFICE1111111111PHONE
    329709REOFFICEROB29709REOFFICE2223334444OFF
    429709REOFFICEROB29709REOFFICE5556667788FAX
    51234REOFFICEMIKE

    I want id 29709 agent in a line with 1234 agent also id to display

    You can rotate your phone number of agent in columns

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788

    Then you can join to view inline or CTE

    with AGENT_PHONE_PIVOT like)

    Select *.

    of AGENT_PHONE

    pivot)

    min (PHONE_NUMBER)

    for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')

    )

    )

    SELECT *.

    AGENTS HAS

    LEFT OUTER JOIN AGENT_PHONE_PIVOT AP

    ON A.AGENT_ID = AP. AGENT_ID

    AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.

    AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.

    AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX
    29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788
    1234 RE OFFICE MIKE - - - - - - -

    Is that what you're looking for?

  • Tuning for sql join key table no consumer of the heavy use of the query processor

    Obligation comes to tunne prod of the query in

    high use of the query processor

    sql_id: fp79wb32h7a6t

    Module: AHC, P_PatientDQ()

    Cost: 7

    Elapsed time: hung

    Status: Hung, 35,253,460 day at 30 minute intervals

    -Create table

    create table ahc. PATIENTVISITS

    (

    ahcid NUMBER,

    visitId NUMBER,

    visitstatus NVARCHAR2 (100),

    visitdate DATE,

    visitintime DATE,

    visitouttime DATE

    )

    -Create/recreate the index

    create indexes ahc. F1_PATIENTVISIT_AHCID on ahc. PATIENTVISITS (AHCID, VISITID);

    create indexes ahc. VISITDATE_IDX on ahc. PATIENTVISITS (TRUNC (VISITDATE));

    First total number of table

    Select count (1) of

    Pvs AHC.patientvisits

    -Save County 1387485

    create table ahc. PATIENTDEPENDENTVISITS

    (

    ahcid NUMBER (19) not null,

    IDPack NUMBER (10) not null,

    visitId NUMBER (19) not null,

    dependentvisitid NUMBER (19) not null,

    isdiabetic NUMBER (2)

    )

    -Create/recreate the index

    create indexes ahc. K1_PATIENTDEPENDENT_AHCID on ahc. PATIENTDEPENDENTVISITS (AHCID);

    Total number of second table

    Select count (1) of

    AHC.patientdependentvisits POS

    -Save County 774599

    Original request:

    SELECT count (*)

    ACH. PVS PATIENTVISITS

    WHERE PVS. VISITID IN (SELECT POS. DEPENDENTVISITID

    ACH. PATIENTDEPENDENTVISITS POS

    WHERE POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0)

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    AND PVS. AHCID = 37

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for the original query

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, GOAL = ALL_ROWS7141636697
    AGGREGATION OF TRI141
    SEMI OF THE NESTED LOOPS7141636697
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS4125332954
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID39231643
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS3116303753
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID214180932

    After editing the query

    SELECT / * + FIRST_ROWS * / COUNT (1)

    ACH. PVS PATIENTVISITS

    JOIN THE AHC. PATIENTDEPENDENTVISITS POS ON PVS. VISITID = POS. DEPENDENTVISITID

    WHERE PVS. AHCID = POS. AHCID

    AND POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for change request

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, TARGET = TIP: FIRST_ROWS7141592577
    AGGREGATION OF TRI141
    NESTED LOOPS
    NESTED LOOPS7141592577
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS4116366464
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID314243643
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID21152932
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS3125226113

    here after I changed the query no display cost = 7 io wait = improvement also 7 can someone please help these

    How to adjust or rewrite lots of join not keys to multiple records on table table

    Thank you

    VSM

    you have not answered my question. Are you really calling it 35 million times in 30 minutes?

    If so, why?

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

  • Join the tables in the responses

    I would like to know if it is possible to join the tables together as below in the answers?

    Select a.Field1, b.Field1
    FROM tableA an outer join left tableA b on
    a.Field1 = b.Field

    If you want to make an INNER JOIN, and then type INNER JOIN instead of LEFT INNER JOIN.

    If you want to left outer join and LEFT OUTER JOIN instead of INTERNAL LEFT JOIN type.

    Nothing asked as a left inner join. That is why it gives error + [nQSError: 27002] near +.

    Thank you

  • Join the execution of several Tables Plan

    Try to understand the query execution plan:
     
    
    HR>  SELECT e.last_name , d.department_name, l.city
      2     FROM employees e, departments d , locations l
      3     WHERE e.department_id = d.department_id
      4   AND
      5           d.location_id = l.location_id;
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1235509609
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT              |                  |   106 |  4346 |     9  (23)| 00:00:01 |
    |*  1 |  HASH JOIN                    |                  |   106 |  4346 |     9  (23)| 00:00:01 |
    |   2 |   MERGE JOIN                  |                  |    27 |   837 |     6  (34)| 00:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| DEPARTMENTS      |    27 |   513 |     2   (0)| 00:00:01 |
    |   4 |     INDEX FULL SCAN           | DEPT_LOCATION_IX |    27 |       |     1   (0)| 00:00:01 |
    |*  5 |    SORT JOIN                  |                  |    23 |   276 |     4  (50)| 00:00:01 |
    |   6 |     VIEW                      | index$_join$_003 |    23 |   276 |     3  (34)| 00:00:01 |
    |*  7 |      HASH JOIN                |                  |       |       |            |          |
    |   8 |       INDEX FAST FULL SCAN    | LOC_CITY_IX      |    23 |   276 |     1   (0)| 00:00:01 |
    |   9 |       INDEX FAST FULL SCAN    | LOC_ID_PK        |    23 |   276 |     1   (0)| 00:00:01 |
    |  10 |   TABLE ACCESS FULL           | EMPLOYEES        |   107 |  1070 |     3   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    So he needs to MERGE between DEPARTMENTS (that has been sorted by index) JOIN and (here's the part confusing...) LOCATIONS including oracle used HASH JOIN (?) to bring the information from and then sort the opinion generated by the system that has been created...?

    Is that this HASH JOIN to step 7 only refers to a view that is generated by the system that oracle had to sort and not actually HASH JOIN
    between two tables?

    Thanks much for you patience

    Hello

    Perhaps, it helps to understand things better if we walk in the plan.

    Plans have a hierarchical structure (which is translated graphically by fingerprints). Operating needs parent all the children completed operations before it can do its job (which is generally combining lines with children in one way or another).

    Another point is that joins can have anything like their entries, tables not only. That is a hash join can join an index for an index or a table to an index, or then to join a table results of hash one another and so on and so forth.

    With this in mind, we can go back on what is happening here step by step:

    The needs of the join by hash (1) (2) and (10) to finish. (10) is a basic operation, since a table scan depends on nothing else, but merge join handset (2) (3) and (5), who both are complex operations (i.e. dependent on one or more children). Specifically, lines (3) from the DEPARTMENTS table using ROWID obtained from a full analysis of the index of DEPT_LOCATION_IX (4), (5) is simply lines join hash (7) and sorted in the order required.

    I hope this helps.

    Best regards
    Nikolai

    Published by: Nikolay Savvinov on January 26, 2012 05:26

  • How to join the table in screens LCD

    Hello

    How can I join the tables in the screens LCD and show them in a datagrid?

    I run LCDS3 and tomcat.

    Any help is appricitated

    User (name, surname, address)

    Address (address, State, country, postal code)

    If you want to display data below in your data grid

    ---------------------------------------------------------------------------

    firstName.       lastName.  State

    ---------------------------------------------------------------------------

    user.firstName | user.lastName | User.Address.State

  • INVENTORY and ORDERS tables MANAGEMENT join the requirements

    Hi all

    I need to create a point of view, to display item_description item_number, quantity_in_warehouse and pendingquantity_in_salesorder.

    query is based on the INVENTORY & ORDERS of tables. I wrote under query, it does not give the expected results. Please go through once and correct me if I did any wrong thing while writing the join conditions.


    SELECT mtlb.segment1 Item_Number,
    mtlb. Item_Description description,
    mTLD.transaction_quantity Quantity_in_Wearhouse,
    OEL.ordered_quantity PendingQuantity_in_SalesOrder
    OF mtl_system_items_b mtlb.
    mtl_onhand_quantities_detail mtld,
    OEH oe_order_headers_all,
    oe_order_lines_all oel
    WHERE mtlb.inventory_item_id = mtld.inventory_item_id
    AND mtlb.organization_id; = mtld.organization_id
    AND mtlb.inventory_item_id; = oel.inventory_item_id
    AND oeh.header_id; = oel.header_id
    AND oeh.org_id; = oel.org_id
    AND oeh.ship_from_org_id; = mtlb.organization_id
    AND oel.ship_from_org_id; = mtlb.organization_id
    AND mtld.subinventory_code AS "warehouse".
    AND oel.flow_status_code AS 'AWAITING_SHIPPING '.
    ORDER BY mtlb.segment1;

    There is little urgency. Please help me solve this problem.

    Thank you.

    Published by: user627525 on July 19, 2010 04:35

    Just replace xxx in the query with your organization_id-

    SELECT
    MSI. As Item_Number Segment1
    msi.description as Item_Description
    SUM (ool.ordered_quantity) AS SO_quantity
    AVG (oh_qty) as on_hand
    Of
    (SELECT
    MSI.inventory_item_id, msi.organization_id, SUM (ohd.primary_transaction_quantity) AS oh_qty
    Of
    MSI mtl_system_items_b
    JOIN ohd mtl_onhand_quantities_detail WE
    (msi.inventory_item_id = ohd.inventory_item_id AND msi.organization_id = ohd.organization_id)
    WHERE ohd.subinventory_code = 'Warehouse' AND msi.organization_id = xxx GROUP BY msi.inventory_item_id, msi.organization_id) Q1
    JOIN THE
    oe_order_lines_all ool ON (q1.inventory_item_id = ool.inventory_item_id AND q1.organization_id = ool.ship_from_org_id)
    JOIN oe_order_headers_all ooh WE (ool.header_id = ooh.header_id)
    JOIN msi mtl_system_items_b IT (ool.flow_status_code = 'AWAITING_SHIPPING' AND ool.inventory_item_id = msi.inventory_item_id AND ool.ship_from_org_id = msi.organization_id)
    GROUP OF msi.inventory_item_id, msi.segment1, msi.description
    ORDER BY msi.segment1

  • The ANSI syntax for the join 4 tables-is this correct?

    Hi, I'm new to these forums and I have looked everywhere and cannot find the syntax and examples on how to join the tables 2 and 3 using the ANSI standard, but I need to reach 4. For a traditional join, it would be:

    SELECT a.two b.one, b.three, b, a.one, d.seven
    Tablea, tableb b, c in tablec, deposited d
    WHERE a.one = b.one
    AND a.two = c.two
    AND c.six = d.six;

    Here are the tables:

    TableB
    one
    three
    four

    TableA
    one
    two

    TableC
    two
    six

    deposited
    six
    seven
    eight

    Anyone know how to do this by using an ANSI join or have all of the resources that can guide me in the right direction. I don't know if I wanted to join three tables, it would be:

    SELECT a.two b.one, b.three, b, a.one, c.six
    FROM tableb b JOIN tablea one WE b.one = a.one JOIN tablec c ON a.two = c.two;

    so join a fourth would:

    SELECT a.two b.one, b.three, b, a.one, d.seven
    FROM tableb b JOIN tablea one WE b.one = a.one JOIN tablec c ON a.two = d JOIN filed c.two ON c.six = d.six;?

    Is the above correct or is there another way to do this, use an ANSI join?

    Published by: user1076466 on October 17, 2009 17:40

    Hello

    your JOIN looks good,

    "FROM tableb b JOIN tablea one WE b.one = a.one JOIN tablec c ON a.two = d JOIN filed c.two ON c.six = d.six" you get a different result set?

    Thank you

  • [Help] Join the query from 3 tables

    Hi, I'm new to database. I have a question about joining 3 tables, forgive me for my bad English.

    My paintings look like this

    Table 1: person (id, firstname, lastname)
    Table 2: AssignPersonAddress (id, personid, addressid, type)
    Table 3: address (id, phone, street, etc.)

    I need AssignPersonAddress table, because in my data structure, a person may have more than 1 address and address type must be registered (for example: private, work)


    I want to do a select query to the State any person with his private phone and work phone, like this.
    NOBODY | PRIVATE | WORK



    Right now my query looks like this
    select p.name , a1.tel AS Private, a2.tel AS Work
    from person p, 
    addresse a1 , 
    AssignPersonAddress apd1, 
    AssignPersonAddress  apd2, 
    addresse a2
    
    where p.id  = apd1.person (+)
    and apd1.adresse  = a1.id 
    and apd1.art = 'Private' 
    and p.objectid = apd2.person (+)
    and apd2.adresse  = a2.id 
    and apd2.art = 'Work'
    the problem is that I only get the person who has a private address and the job. But what I want is all anyone no matter if the person has only 1 or 2 address.

    As you can see I put the left outer join in where condition, but I always get the wrong result.


    THX in advance


    Danny

    Published by: raitodn on October 1st, 2009 03:51

    Published by: raitodn on October 1st, 2009 04:12
  • Join the table orders from clause

    Hi all

    Who is the effective way to join the tables in from clause. I have two tables first with 20 lakh records and second containing 10 lakh recods.
     
    QUERY 1:  SELECT T4.ID,T4.ISO_NAME  FROM T,T4 
    WHERE T4.ISO_NAME LIKE '%US%' AND T.ID=T4.ID;
    
    QUERY 2:  SELECT T4.ID,T4.ISO_NAME  FROM T4,T 
    WHERE T4.ID=T.ID AND  T4.ISO_NAME LIKE '%US%';
    
    T(ID IS PRIMARY KEY) 
    (20 lakh records)
    
    T4 (ID IS PRIMARY KEY ) 
    (10 lakh records)
    ---------------------
    ID     ISO_NAME
    100  US,UK,IN,BR
    101  UK,US,BR,IN
    102  BR,UK,US,IN
    
    
    Note: No index on ISO_NAME .
    Who is the effective query 1 or 2. Please suggest me if you have an idea to rewrite the query.



    Kind regards
    Rajasekhar

    Published by: SuNRiZz68 on January 29, 2009 04:22

    In practical terms, Alex is right. Sometimes it matter what table is selected first, but does the CBO generally a very good job of deciding what you need to select the first (assuming that your statistics are up to date) but this is the situation you are trying to avoid as much as possible.

    If you specify a table main command tables in the clause is not reliable and should be used - but think before using advice and don't do that when necessary.

    Which table to select depends firstly on the join method in the execution plan. Nested loops joins perform better by selecting in the smaller table first, make a loop on the largest table. Joins the smaller set hash table in memory first, and then go through the larger table, perform searches in memory. He can't make any difference, what table is read using first the merger joins and sort.

    Back to your original question. Using the cost-based optimizer, both queries will probably roll the same because newer versions of Oracle (9i, 10g) often transform queries for efficiency before the execution anyway. According to what do you or do not request should probably run a nested loop or hash join. With a small set of data creaing index and using a search of nested loops will probably be faster to avoid full table scans. the '%' in the LIKE clause leader would ignore an index on the ISO_NAME column in any case if a main column may be used in a composite index. All this is based on the approximation using the information provided; Tuning questions should always be tested to unexpected developments.

  • Unable to join the homegroup on new Inspiron 15 5559

    I had a residential group put in place for a good while on 3 computers desktop and an old Tower, but my new laptop Dell Inspiron 15 5559 with 10 Windows fails to reach.  I get to the point of putting in the right password and clicking NEXT, then the bar keeps of moving from left to right for several minutes, then stops without any messages and not to join.

    Here are the details.  Computer of One Office (a Dell Inspiron 630 with Windows 7 Pro), a former HP with Windows Pro 10 office, an old house built office with Windows 10 Pro (64-bit), and an old Toshiba laptop with 64 bit Windows 7 Home.  All these joined the homegroup very well.  In addition to the homegroup, I have the file & printer sharing power with 4 of them.  On the Dell desktop computer, I have 9 folders and two shared printers.  The new laptop Dell can access shared folders, it is just unable to join the homegroup.  I created the homegroup because I had problems to access 2 shared printers (a Canon IP1600 inkjet and laser Samsung ML-2525) with 10 windows, in case you're wondering why I'm not just with the file & printer sharing instead of homegroup.

    In any case the key is that everything on this new Dell laptop works fine except that I can not join the homegroup, and I'm very curious as to why not.  I did full virus scans with Defender and Norton 360 and have done two scans with MalwareBytes, but no malware has been found.  I also ran "SFC/scannow" and it found no problem either.  I checked to make sure that I put in the security key for the homegroup, and at this point, I am triple ideas.  It please does not restore to the factory settings, because I had this problem since the first day that I got this laptop out of the box before I did any customization. FWIW, I'm no novice in computer science.

    What suggest you?  TIA

    Yesterday I posted a note that I would have found and solved the problem.  I don't know what happened to this post.  The problem was that there was a popup that was actually a pop-under hidden behind a number of open windows.  He said that there was an invalid password.  Of course the note that I had used to set up 4 PCs had a "n" where there is now a "m".  I would like to say that this has changed from n to m somehow otherwise I don't know how I was able to put in place the other 4 PCs.  Anyhoo, the problem is now resolved.

  • Join the results of a case statement

    Hello everyone;

    I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column.  I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended.  It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.

    My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID).  In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID.  I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table.  The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.

    My current query:

    SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.

    dbin.snapshot_date, dbin.bin_id, dbin. ISBN,

    CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID

    Of ANOTHER sku. ProdID

    END ProdIDMaster,

    dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,

    MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,

    MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume

    OF D_BIN_ITEMS dbin

    SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU

    LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)

    WHERE REGION_ID = 1

    AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID

    ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU

    LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)

    WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr

    ON ProdIDMaster = msr. ProdID

    WHERE dbin. WAREHOUSE_ID = "PHL5."

    AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')

    AND dbin.bin_id like '% P-1-R '.

    ORDER BY dbin.bin_id;

    The error I receive:

    Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier

    ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement.  If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.

    Any help or advice would be greatly appreciated.

    Post edited by: 8ea4344e-80ea-44e7-b8ac-d482be7245a7 I made a mistake when I posted the code.  The ProdID_ID shown in the join should have been ProdIDMaster.  I need to change this due to the fact that the name of the column used (which is what I based my alias on) may have been considered confidential information. All the other columns names remained unchanged.

    Hello

    8ea4344e-80EA-44e7-B8AC-d482be7245a7 wrote:

    Hello everyone;

    I can't with a query where I use a case statement to create a new column and attempt to reach an additional table on the resulting column.  I am fairly new to this and learn by trial and error, so if you think that it looks a little ugly or ineffective, I won't be offended.  It is used on my interface based on the web of companies, while I am not able to answer some basic questions such as the version of db.

    My need to use the case statement is the result of some strange methods and somewhat contradictory in order to link the product subcodes (sku, fcsku, fnsku), to a product code parent (ProdID).  In this case, the inventory is stored in the first table with one of the few types of premises SKUs, however the dimensional data only links to the ProdID.  I'm trying to instruction box allows to send the parent a second table (ProdID) code if the sku is there, or a third table if it is found on this table.  The main reason (in this case) I have to this ProdID is I can join the dimensional data of a fourth table.

    My current query:

    SELECT / * + USE_HASH (dbin, sku, xProdID, msr) * /.

    dbin.snapshot_date, dbin.bin_id, dbin. ISBN,

    CASE WHEN sku. ProdID IS NULL THEN xProdID.ITEM_AUTHORITY_ID

    Of ANOTHER sku. ProdID

    END ProdIDMaster,

    dbin. OWNER, dbin. QUANTITY, dbin. CONTAINER_ID,

    MSR. HEIGHT, msr. WIDTH, msr. LENGTH, msr. WEIGHT, msr. DIMENSIONAL_UOM, msr. WEIGHT_UOM,

    MSR. HEIGHT * msr. WIDTH * msr. LENGTH as a Volume

    OF D_BIN_ITEMS dbin

    SKU of LEFT JOIN O_FCSKUS ON dbin. ISBN = sku. FCSKU

    LEFT JOIN (SELECT * FROM D_FNSKU_ProdID_MAP)

    WHERE REGION_ID = 1

    AND SNAPSHOT_DAY = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')) xProdID

    ON dbin. ISBN = xProdID.FULFILLMENT_NETWORK_SKU

    LEFT JOIN (SELECT * FROM D_MP_ProdID_PKG_MEASUREMENTS)

    WHERE REGION_ID = 1 AND MARKETPLACE_ID = 1 AND PACKAGE_TYPE_ID = 1) msr

    ON ProdIDid_ID = msr. ProdID

    WHERE dbin. WAREHOUSE_ID = "PHL5."

    AND dbin. Snapshot_date = TO_DATE('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD')

    AND dbin.bin_id like '% P-1-R '.

    ORDER BY dbin.bin_id;

    The error I receive:

    Statement 1 is invalid. ORA-00904: "ProdIDMaster": invalid identifier

    ProdIDMaster appears only in two places, an alias for the case statement, as well as a side of the join statement.  If I simply change the alias name, it has no effect, so I can only assume the question is how I refer to results of the case statement. I also tried to reach the word 'CASE', which returned "1 statement is not valid. "ORA-00904:"The MATTER": invalid identifier.

    Any help or advice would be greatly appreciated.

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).  Use "SELECT * VERSION of $ v;" to get it.

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    When you define an alias for column (such as PriodIDMaster) in the SELECT a query clause, you can use the alias in the ORDER byclause in this request, but this is the only place in this same query, where you can use it.  If you want to use anywhere, like in a join condition, then calculate the new column in a subquery; then you can use it anywhere you want in a Super request.

    I see expression BOX (not the same as a declarationBOX) where when ProdIDMaster is defined, but I do not see where it is used.  Are you sure that you posted the code that is causing the problem?

  • Join the nearest date "not used".

    I need to join the following tables by the next date "not previously signed" the nearest:

    start_table:

    st_id start_dt
    start031-dec-2014
    Start1

    January 3, 2015

    Start2January 5, 2015
    start3January 7, 2015
    Debut48 January 2015
    Debut5January 14, 2015

    end_table:

    end_id end_dt
    end0January 1, 2015
    End1January 2, 2015
    End2January 13, 2015
    End3January 15, 2015
    bout4January 17, 2015
    end519 January 2015
    end6January 20, 2015

    Result:

    st_id end_id
    start0end0
    Start1End2
    Start2End3
    start3bout4
    Debut4end5
    Debut5end6

    start0 joined end0, because the closer to the date of the next 31-dec-2014 is 1 January 2015

    Start1 joined end2, because the closer to the date of the next January 3, 2015 is January 13, 2015.

    Start2 joined end3, because as well as the date of the next more close January 5, 2015 is 13 January 2015, this is already accompanied Start1, so she joined next January 15, 2015.

    start3 joined bout4, because the date of the next although most close January 7, 2015 is 13 January 2015, this one is already joined by Start1, earliest date is January 15, 2015, but is also already joined by start2, then he joined the next available date January 17, 2015.

    Database: 11g

    Thanks in advance

    [UPDATE: changed line 37 to add "or cnt > = 0".] [This covers cases where there are more departures that ends at first.]

    Jiri.Machotka - Oracle wrote:

    I found a non recursive algorithm for this problem...

    I came up with something similar: no recursion, no joins, each table read only once.

    1. UNION ALL marked times 1 tables, with lines of departure and end marked lines - 1
    2. Order by date (first lines) and get a combination of 1's and - 1's.
      so when there are too many lines to end, the sum is negative.
    3. Get the previous cumulative minimum! Then take that end with a sum running lines, at less than the previous minimum.
    4. The remaining lines will have an end of line for each line of departure. Now number lines starting from 1 to N and the lines at the end of 1 to N, then match lines start and end in pairs. I use PIVOT to do this.
    WITH end_table (end_id, end_dt) AS (
      select 'end0',to_date('01-jan-2015','dd-mon-yyyy') from dual union all
      select 'end1',to_date('02-jan-2015','dd-mon-yyyy') from dual union all
      select 'end2',to_date('13-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end3',to_date('15-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      select 'end4',to_date('17-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end5',to_date('19-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      SELECT 'end6',to_date('20-jan-2015','dd-mon-yyyy') FROM dual
    )
    ,start_table (start_id, start_dt) AS (
      select 'start0',to_date('31-dec-2014','dd-mon-yyyy') from dual union all
      select 'start1',to_date('03-jan-2015','dd-mon-yyyy') from dual union all
      select 'start2',to_date('05-jan-2015','dd-mon-yyyy') from dual union all
      select 'start3',to_date('07-jan-2015','dd-mon-yyyy') from dual union all
      select 'start4',to_date('08-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'start5',to_date('14-jan-2015','dd-mon-yyyy') FROM dual
    )
    , start_and_end as (
      select -1 rowtype, end_id id, end_dt dt from end_table
      union all
      select 1, s.* from start_table s
    )
    , running_count as (
      select se.*,
        sum(rowtype) over(order by dt, rowtype desc) cnt
      from start_and_end se
    )
    , filtered_ends as (
      select rowtype, id, dt from (
        select rc.*,
          min(decode(rowtype,-1,cnt)) over(
            order by dt, rowtype desc
            rows between unbounded preceding and 1 preceding
          ) mincnt
        from running_count rc
      )
      where cnt >= nvl(mincnt,0) or cnt >= 0
    )
    select * from (
      select rowtype, id,
      row_number() over(partition by rowtype order by dt) rn
      from filtered_ends
    )
    pivot(max(id) for rowtype in(1 st_id, -1 end_id))
    order by rn;
    

    ST_ID END_ID RN

    ---------- ------ ------

    1 start0 end0

    2 Start1 end2

    3 Start2 end3

    4 start3 bout4

    5 debut4 end5

    Debut5 6 end6

  • Join the 2 queries with common group by column

    IAM trying to reach the results of 2 queries. Myu first query returns as follows.

    Like, second

    I need to show together and I wrote the request to the below:

    Select b.br_id, count (b.mech_code), sum (b.labour_cost), count (a.received_by) in table2 b, table1: a group of b.br_id;

    But it doesn't show any errors or shows no results. It just continues the treatment forever. Plese help

    Just joined the group two by queries later

    Select

    b.br_id

    b.cnt_mech_code

    b.sum_lc

    a.cnt_rcvd

    de)

    Select

    b.br_id

    count (b.mech_code) cnt_mech_code

    sum (b.labour_cost) sum_lc

    from table2 b

    B.br_id group

    ) b

    , (

    Select

    Count (a.received_by) cnt_rcvd

    Table 1A

    A.br_id group

    ) a

    where

    b.br_id = a.br_id

Maybe you are looking for