Join of two tables

Hi all

I have two tables - TableA and TableB

I need all these records in TableA that have no matching records in TableB based on Key1, Key2, and Key3 and process them further.

Can someone help pls?

Hello 954475

Try this:

SELECT A.*

FROM TableA A

WHERE DOES NOT EXIST (SELECT 1

FROM TableB B

WHERE A.Key1 = B.Key1

AND A.Key2 = B.Key2

AND A.Key3 = B.Key3

)

;

I hope that helps!

Tags: Database

Similar Questions

  • Join of two tables in two different schemas

    Hi all

    I have an obligation to join two tables on two different schemas. How to join these two tables in the object view.

    Thanks in advance.

    Concerning
    Kaushik Guillaumin

    You can do just that using schema name in the +' view object.table name ' + according to the query object and also grant select the another schema to this schema user

    ex
    you need schem is test and another Act you need to a view object based on the test to join a table on shcema Act

    you write semply object sql view code:

    Act.table name

    and you can also give him select statement on Bill schem table to test

    concerning

  • problem with join of two tables

    Hi, consider the following data
    WITH data AS
    (
      SELECT 123 cid, 'aaa' isi, 'kkk' sud, 'ttt' ri FROM dual UNION ALL 
      SELECT 222 cid, 'bbb' isi, 'gggg' sud, 'hhh' ri FROM dual
    
    ) ,
    data2 AS 
    (
      SELECT 'aaa' isi, 'yyy' sud, 'ooo' ri FROM dual UNION ALL 
      SELECT 'qqq' isi, 'ggg' sud, 'ooo' ri FROM dual UNION ALL 
      SELECT 'uuu' isi, 'ppp' sud, 'ttt' ri FROM dual UNION ALL
       SELECT 'ppp' isi, 'mmm' sud, 'nnn' ri FROM dual 
    
    
    )
    what I want to do, is to join data2 with data by isi, ri or southern id table and produce this output.
     cid  txt
     ===  ====
     123  aaa
     222  ggg
     123  ttt
    It's how I got the above output:
    first try to join isi in database2 with isi in "features" and discover if line matches. If this is the case, display the cid of the data table and the use of the value to match.
    e.g. in the first line of table data2, we can see that isi = aaa matches line an isi data table. If the output displays 123 and value aaa.

    If the rank table two of the Data2 isi = qqq. When join them with the data table, we find not all isi with qqq. in this case, it must join with column of South. We can see that South = ggg data2 games
    the second line in the table of output so will bee 222 and value ggg.

    now, take a look at the third row in Database2. ISI = uuu is not found in the data table when join them. then try to join to the South. South = ttt is also not found in any row of the data table. so join with ri. We
    can see that ri = ttt data2 matches with ri = ttt in the table of data online 1. Therefore, we display the value.

    can someone help me write a sql query that joins these two tables by isi. If no line found then join South, if no found rows then join in ri? Thank you

    Hello

    elmasduro wrote:
    Hi Frank, data2.sud = 'Gay' (4 characters) assume to be South = "ggg". by mistake, I type extra g.

    I have another question about the request. What happens if I want to bring rows of data.2 even if they do not exist in the data table for the entire column was join?
    for example, I want to show this:

    cid  txt
    ===  ====
    123  aaa
    222  ggg
    123  ttt
    ppp  --row from data2
    

    the columns of the last row of data.2 does not match any column in the data table. in this case, I want to make but cid will be null. I tried outer join on your request, but it looks like I can not clause or with outer join

    SELECT     d1.cid
    ,     CASE
              WHEN  d1.isi = d2.isi  THEN  d2.isi
              WHEN  d1.sud = d2.sud  THEN  d2.sud
                                            ELSE  d2.ri
         END     AS txt
    FROM data     d1
    JOIN     data2     d2  ON     d1.is(+)i     = d2.isi
                  OR     d1.sud(+)     = d2.sud
                  OR     d1.ri(+)     = d2.ri
    ;
    

    How can I re - write the query for this case? Thanks again for your help

    Here is the outer join syntax:

    SELECT     d1.cid
    ,     CASE
              WHEN  d1.isi = d2.isi  THEN  d2.isi
              WHEN  d1.sud = d2.sud  THEN  d2.sud
              WHEN  d1.ri  = d2.ri   THEN  d2.ri
                                            ELSE  d2.isi
         END     AS txt
    FROM          data2     d2
    LEFT OUTER JOIN     data     d1  ON     d1.isi     = d2.isi
                           OR     d1.sud     = d2.sud
                           OR     d1.ri     = d2.ri
    ;
    

    The + sign for outer joins only works with the old join syntax, non-ANSI. Do not try to mix the two different ways to do joins.

    Not to mention that the outer join, don't forget to change the CASE expression, to include the new possibility of any columns 3 join matching.

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • Please, help me to join of two tables?

    Hello..

    I'm using oracle 11g.

    I have two tables with below description

    1.esb_v_study_personnel

    study_code_alias varchar2,

    Site_ID number,

    role_at_site_level_desc varchar2

    2 esb_v_study_site

    study_code_alias varchar2

    Site_ID

    I'm counting the role_at_site_level_desc where it is'Monitor' or 'primary monitor'

    So I wrote the following query

    Select study_code_alias, site_id,.

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order by study_site_id

    using the above, I'm getting lines of 1617.

    but I want to map the resultant site_id

    esb_v_study_site with lines of 1647. If I want to get all the site_id in esb_v_study_site table mapping to above query.

    Can you guide me on this point.

    I tried with a left outer join, but still iam getting lines of 1617.

    Select study_code_alias,

    no_of_study_monitors (role_at_site_lvl_desc)

    esb_v_study_site_personnel

    study_code_alias IN & arg_trial_code

    role_at_site_lvl_desc in ()"Monitor" "Main screen"()

    Group of study_code_alias, study_site_id

    order of study_site_id) a

    LEFT OUTER JOIN

    ON a.trial_no = d.trial_no et a.study_site_id = d.study_site_id

    d.study_code_alias in & arg_trial_code

    Group by d.study_code_alias, d.study_site_id, a.no_of_study_monitors

    order by d.study_site_id

    Please help me on this?

    I'm not quite sure, because your query seems to us of small missing pieces. He was probably down during some copy & paste on this forum.

    I guess the reason is that the left join is performed after the group where the count on the column does not count NULL values that might be created by the outer join.

    Maybe you can start with the following query and give us the results and tell us if it is always wrong and what the outcome would be expected.

    example (not tested the syntax)

    select  d.study_code_alias
        ,d.site_id
       , count(a.role_at_site_lvl_desc) no_of_study_monitors
       , count(distinct a.role_at_site_lvl_desc) no2
       , count(*) no3
    from esb_v_study_site d
    left join esb_v_study_site_personnel a on a.trial_no=d.trial_no and a.study_site_id=d.study_site_id and a.role_at_site_lvl_desc in ('Field Monitor','Primary Monitor')
    where d.study_code_alias IN (&arg_trial_code)
    group by d.study_code_alias,d.study_site_id
    order by d.study_site_id;
    

    BTW: If you read the FAQ in the upper right corner, here, he said how well sql zip code search.

  • help the join of two tables

    Hello

    I need your help in the script below:

    I have two tables.

    My "table1" table contains the data below:

    Code:

    Name, Value
    ------------
    12 A, 1
    12 B, 1
    12 C, 1



    Table2 contains the following data:

    Code:

    value, result
    ------------
    1.12
    1.24
    1.56
    1 423
    1.32
    1, 3




    I need to join based on a field value.

    My result is:

    Code:


    NAME, VALUE, RESULT
    -------------------------
    12 A, 1, 12
    12 B, 1: 24
    12 C, 1, 56
    12d, 1, 423
    12TH, 1, 32
    12F, 1, 3





    Based on the number of records in the second table, it must add A to Z at the end of the name field. The number of records exceeds no more than 26. How can we achieve this?


    _________________

    Thank you
    Pocard

    OK, now you give other useful information - that there always will be combinations of amounts in table2 to match values in table1. (It is difficult to help when you say the specs one both :-))

    But it is not easy, because the code should really try to consider all combinations and then 'choose the right' - it's easy for us humans, but not easy to code in the programming logic.
    I made an attempt:

    SQL> set linesize 120
    SQL> with table1 as (
      2     select 'A1' name, 123 id, 150 value from dual union all
      3     select 'A2' name, 123 id, 200 value from dual union all
      4     select 'A3' name, 123 id, 300 value from dual
      5  ), table2 as (
      6     select 123 id, 100 value from dual union all
      7     select 123 id, 100 value from dual union all
      8     select 123 id, 50  value from dual union all
      9     select 123 id, 100 value from dual union all
     10     select 123 id, 100 value from dual union all
     11     select 123 id, 100 value from dual union all
     12     select 123 id, 100 value from dual
     13  )
     14  --
     15  -- End of test data
     16  --
     17  select
     18  t1.id, t1.name, t1.value, t2.value,
     19  t1.rn, t1.minval, t1.maxval,
     20  t2.rn, t2.sumval
     21  from (
     22     select
     23     tab1.*,
     24     nvl(sum(tab1.value) over (
     25        partition by tab1.id
     26        order by tab1.rn
     27        rows between unbounded preceding and 1 preceding
     28     ),0) minval,
     29     sum(tab1.value) over (
     30        partition by tab1.id
     31        order by tab1.rn
     32        rows between unbounded preceding and current row
     33     ) maxval
     34     from (
     35        select
     36        table1.*,
     37        row_number() over (
     38           partition by table1.id
     39           order by table1.value desc
     40        ) rn
     41        from table1
     42     ) tab1
     43  ) t1
     44  join (
     45     select
     46     tab2.*,
     47     sum(tab2.value) over (
     48        partition by tab2.id
     49        order by tab2.rn
     50     ) sumval
     51     from (
     52        select
     53        table2.*,
     54        row_number() over (
     55           partition by table2.id
     56           order by table2.value desc
     57        ) rn
     58        from table2
     59     ) tab2
     60  ) t2
     61  on (t2.id = t1.id)
     62  where t2.sumval > t1.minval
     63  and t2.sumval <= t1.maxval
     64  order by
     65  t1.id,
     66  t1.rn,
     67  t2.rn
     68  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
           123 A3        300        100          1          0        300          1        100
           123 A3        300        100          1          0        300          2        200
           123 A3        300        100          1          0        300          3        300
           123 A2        200        100          2        300        500          4        400
           123 A2        200        100          2        300        500          5        500
           123 A1        150        100          3        500        650          6        600
           123 A1        150         50          3        500        650          7        650
    
    7 rows selected.
    

    It doesn't seem to work for your sample data, but it is much too simple a rule at work in general. My "rule" is simply of sorts data according to the value descending and adding up to what 'enough' of values have been added.

    Consider this example of data instead of this:

    SQL> with table1 as (
      2     select 'A1' name, 1 id, 100 value from dual union all
      3     select 'A2' name, 1 id, 200 value from dual union all
      4     select 'A3' name, 1 id, 300 value from dual union all
      5     select 'B1' name, 2 id, 100 value from dual union all
      6     select 'B2' name, 2 id, 200 value from dual
      7  ), table2 as (
      8     select 1 id, 25  value from dual union all
      9     select 1 id, 75  value from dual union all
     10     select 1 id, 50  value from dual union all
     11     select 1 id, 50  value from dual union all
     12     select 1 id, 175 value from dual union all
     13     select 1 id, 225 value from dual union all
     14     select 2 id, 25  value from dual union all
     15     select 2 id, 50  value from dual union all
     16     select 2 id, 75  value from dual union all
     17     select 2 id, 100 value from dual union all
     18     select 2 id, 50  value from dual
     19  )
     20  --
     21  -- End of test data
     22  --
     23  select
     24  t1.id, t1.name, t1.value, t2.value,
     25  t1.rn, t1.minval, t1.maxval,
     26  t2.rn, t2.sumval
     27  from (
     28     select
     29     tab1.*,
     30     nvl(sum(tab1.value) over (
     31        partition by tab1.id
     32        order by tab1.rn
     33        rows between unbounded preceding and 1 preceding
     34     ),0) minval,
     35     sum(tab1.value) over (
     36        partition by tab1.id
     37        order by tab1.rn
     38        rows between unbounded preceding and current row
     39     ) maxval
     40     from (
     41        select
     42        table1.*,
     43        row_number() over (
     44           partition by table1.id
     45           order by table1.value desc
     46        ) rn
     47        from table1
     48     ) tab1
     49  ) t1
     50  join (
     51     select
     52     tab2.*,
     53     sum(tab2.value) over (
     54        partition by tab2.id
     55        order by tab2.rn
     56     ) sumval
     57     from (
     58        select
     59        table2.*,
     60        row_number() over (
     61           partition by table2.id
     62           order by table2.value desc
     63        ) rn
     64        from table2
     65     ) tab2
     66  ) t2
     67  on (t2.id = t1.id)
     68  where t2.sumval > t1.minval
     69  and t2.sumval <= t1.maxval
     70  order by
     71  t1.id,
     72  t1.rn,
     73  t2.rn
     74  ;
    
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
    ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
             1 A3        300        225          1          0        300          1        225
             1 A2        200        175          2        300        500          2        400
             1 A2        200         75          2        300        500          3        475
             1 A1        100         50          3        500        600          4        525
             1 A1        100         50          3        500        600          5        575
             1 A1        100         25          3        500        600          6        600
             2 B2        200        100          1          0        200          1        100
             2 B2        200         75          1          0        200          2        175
             2 B1        100         50          2        200        300          3        225
             2 B1        100         50          2        200        300          4        275
             2 B1        100         25          2        200        300          5        300
    
    11 rows selected.
    

    In this data set simple ranking by value won't work - it should have been A3: (225,75), A2: (175,25) and A1: (50.50).

    I can't really think of a reasonably easy way to do this in SQL only. Maybe using the clause TYPE would be possible, but not negligible. It is possible, it would be easier to solve this problem in PL/SQL in iterating through a few tables and intelligently to try different combinations, rather than creating all combinations in a huge piece of brute force SQL.

    I'm sorry, Pandeesh, but I can't think a solution easily.
    I might be able to do something, if I fiddled with the problem for a few days, but that would be beyond the scope of this forum. It would be a consultation of employment rather than a little help from the forum :-)

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • Several foreign key joins between two tables

    Hello

    I have a question about the creation of a repository.

    I have a date and a fact dimension. The fact table has about 10 columns in foreign key to the date Dimension.

    In this case I should create 10 aliases to create joins in the physical layer and MDB or y at - it another way to handle this situation.

    I ask this question because 10 aliases can get very confusing for me at the later stage of time when creating reports.

    With the help of OBIEE 10.1.3

    If you want to see in the industry as
    End date, start date, date etc. nearby
    you need to create 10 aliases for this purpose in the physical layer, make them drag in MDB and model, and then drag to the area of topic

    Score pls correct/good

  • How do good group when the join of two tables?

    Hi all

    The slot using join query, I'd like to get an output will depend on the number of 'Classes' (for example: if I want the result for 15 classes, then, he must return to 16 lines from 0 to 16).
    I n query below, I use the group as
    "GROUP BY report_parameters.report_parameter_value  "
    .

    Error that says "this is not group by expression.

    If I have commented here, here he returns 320 rows instead of 16 ranks.

    Could someone help me?

     SELECT 'SUM('
        || 'CASE '
        || 'WHEN edr_class_by_gvw_report_data.bin_id >= ' || report_range_parameters.report_parameter_min_value || ' 
             AND edr_class_by_gvw_report_data.bin_id  < ' || report_range_parameters.report_parameter_max_value || '
            THEN edr_class_by_gvw_report_data.bin_value '    
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || report_parameters.report_parameter_value || '" '    
          FROM report_parameters
          JOIN report_range_parameters
            ON report_parameters.report_parameter_id = report_range_parameters.report_parameter_id 
         WHERE report_range_parameters.report_parameter_id    = 2316    
           AND report_range_parameters.report_parameter_group = 'GVW_GROUP'
           AND report_range_parameters.report_parameter_name  = 'GVW_NAME'
           AND report_parameters.report_parameter_group = 'CLASS'
           AND report_parameters.report_parameter_name  = 'CLASS' 
         GROUP BY
          report_parameters.report_parameter_value  
         ORDER BY  report_range_parameters.report_parameter_min_value ASC;
    Thank you.

    Published by: user10641405 on June 11, 2009 12:23

    Published by: user10641405 on June 11, 2009 12:30

    Hello

    Let me explain what I'm trying to do.
    I want to write a query that produces this output:

    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 0 AND edr_class_by_gvw_report_data.gvw  < 5 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 0"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 5 AND edr_class_by_gvw_report_data.gvw  < 10 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 1"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 10 AND edr_class_by_gvw_report_data.gvw  < 15 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 2"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 15 AND edr_class_by_gvw_report_data.gvw  < 20 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 3"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 20 AND edr_class_by_gvw_report_data.gvw  < 25 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 4"
    

    using data from tables report_parameters and report_range_parameters, which are like your tables.
    Right now, I don't have report_parameters and report_range_parameters tables.
    I need to create and put the data in them that is like your data.
    If I have the same data you have, and if I can produce the results that you want from the data, so I'll post my query, and you can use it.

    I do not see how to INSERT statements like this:

    INSERT INTO "class_by_gvw_report_data"
              SELECT site_id,
                  site_lane_id,
                 site_direction_id,
                site_direction_name,
                  bin_start_date_time,
                  bin_end_date_time,
                  bin_id,
                bin_value
             FROM "class_by_gvw_bin_data"
    

    can help me. Is the table "class_by_gvw_report_data" invloved in this problem? Is this the same as report_parameters or report_range_parameters? If Yes, I need to create it, and put the data into it, so to use the above statement I need all data of "class_by_gvw_bin_data".

    I need to have something that I can run, so that my paintings will have sample data which would result in the desired output.
    I need the CREATE TABLE statements, but I can probably guess what they should be if I have your data. If this isn't the case, I will seek further clarification later.
    I can't guess what your data, and why is it causing problems. If I just do a few data, LII is virtually no chance he's going against hepatitis has a relationship between the tables that are causing you problems of the same nature.

    Please post INSERT statements that I can run and produce the same type of data that is causing problems.

  • Join of two tables or more in a Ref Cursor columns

    Hi all

    I try to display data columns from two different tables in a cursor.

    Here is the code I am trying...
        DECLARE
       v_dname VARCHAR2(100); 
       v_query VARCHAR2(4000); 
       TYPE ref_cur IS REF CURSOR; 
       v_ref ref_cur; 
       
       d_cname VARCHAR2(100); 
       d_salary NUMBER; 
       --v_dname VARCHAR2(100); 
     
    BEGIN 
       SELECT dname
         INTO v_dname
         FROM dept 
         WHERE deptno = 20; 
         
       v_query := 'SELECT v_dname, a.* 
                      FROM customer a ';
                      
        OPEN v_ref FOR v_query; 
        
        LOOP
           FETCH v_ref INTO v_dname, d_cname, d_salary; 
           EXIT WHEN v_ref%notfound; 
           dbms_output.put_line(v_dname||' '|| d_cname||' '|| d_salary); 
        END LOOP; 
    END; 
    /
    
    I'm trying to get the output as below 
    
    RESEARCH   Dave        9000
    RESEARCH   Amy             10000
    RESEARCH   Anita     11000
    RESEARCH   Bob             12000
    RESEARCH   Marwin     5000
    RESEARCH   Shawn     12000
    RESEARCH   chris              8000
    RESEARCH   Henrik      14000
    RESEARCH   Tricia     7000
    RESEARCH   Nita             9000
    How can this be achieved?
    Thank you.

    Published by: polasa on October 31, 2008 10:25

    polasa wrote:
    I'm v_dname as invalid identifier.

    Using the code of origin you have validated, right? This is because you are using dynamic SQL statements where you shouldn't be (the local variable v_dname does not exist under your dynamic SQL is running in).

    Justin

  • Using JOIN to two tables to find records in the second table...

    I always seem to get these types of queries wrong and need a bit of help:

    I have a MARKETER_ACCOUNT relationship table and another table of pending relationships called ACCOUNT_ENROLLMENT.

    I have accounts that can register with a MARKETING agent. They enter the table ACCOUNT_ENROLLMENT pending and a certain Effective Date the active go and then move to the MARKETER_ACCOUNT table. If a relationship ends, it can end in any event if registering with another buyer or if no registration pending they are supposed to be going back to the parent company.

    So I want to find all the records that came back to the parent company (that is, they may not have a case pending in the ACCOUNT_ENROLLMENT of the table, but have an end date in the MARKETER_ACCOUNT table):

    Select * MARKETER_ACCOUNT m
    where M.account_no NOT IN (select E.account_no from ACCOUNT_ENROLLMENT E
    where E.effective_date between 8 December 2009 "-January 7, 2010")
    and M.expiration_date between 8 December 2009 "-January 7, 2010;

    This request is still in progress, and I don't know where I am going wrong. I mean GIVE me all the accounts in the table MARKETER_ACCOUNT that have a date of expiry from December 7, 2009 "-January 7, 2010 ' and where these accounts are NOT pending in the ACCOUNT_ENROLLMENT table, where the entry into force is for the same period."

    Any help would be greatly appreciated.

    Sean

    Perhaps you could try the version NOT EXISTS in the query:

    SELECT  *
    FROM    MARKETER_ACCOUNT M
    WHERE   NOT EXISTS
            (
                    SELECT  NULL
                    FROM    ACCOUNT_ENROLLMENT E
                    WHERE   M.ACCOUNT_NO = E.ACCOUNT_NO
                    AND     E.EFFECTIVE_DATE BETWEEN TO_DATE('08-DEC-2009','DD-MON-YYYY') AND TO_DATE('07-JAN-2010','DD-MON-YYYY')
            )
    AND     M.EXPIRATION_DATE BETWEEN TO_DATE('08-DEC-2009','DD-MON-YYYY') AND TO_DATE('07-JAN-2010','DD-MON-YYYY');
    

    If not, check out these discussions:

    {message: id = 1812597}

    {: identifier of the thread = 863295}

  • Join of two tables without Cartesian?

    --------------------------------------------------------------------------------------------------------
    SELECT BAGLANTIDATE, CABONE
    FROM SEDEF_BILGI
    WHERE CABONE = '1' AND
    BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    --------------------------------------------------------------------------------------------------------
    BAGLANTIDATE                CABONE
    ------------------------- ---------- 
    10-JUN-09 03.01.52.546000000 AM 1          
    10-JUN-09 05.02.06.453000000 PM 1          
    10-JUN-09 01.01.20.421000000 PM 1          
    10-JUN-09 07.01.42.062000000 AM 1          
    10-JUN-09 09.44.59.515000000 AM 1          
    10-JUN-09 09.58.07.843000000 AM 1          
    10-JUN-09 09.01.50.546000000 PM 1          
    
    7 rows selected
    -----------------------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------------------
    SELECT KAYITDATE, ABONE
    FROM GPRS_TB_SAYACISEMRI
    WHERE ABONE = '1' AND
    KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    ------------------------------------------------------------------------------------------------------------
    KAYITDATE                   ABONE
    ------------------------------------- -------------------
    10-JUN-09 09.52.57.796000000 AM 1
    10-JUN-09 02.13.32.343000000 PM 1
    
    2 rows selected
    I need a code that will help me to show the 9 values in the following form
    BAGLANTITARIH        ABONE
    ------------------------      ----------------
    10-JUN-09 03.01.52.546000000 AM 1          
    10-JUN-09 05.02.06.453000000 PM 1          
    10-JUN-09 01.01.20.421000000 PM 1          
    10-JUN-09 07.01.42.062000000 AM 1          
    10-JUN-09 09.44.59.515000000 AM 1          
    10-JUN-09 09.58.07.843000000 AM 1          
    10-JUN-09 09.01.50.546000000 PM 1    
    10-JUN-09 09.52.57.796000000 AM 1
    10-JUN-09 02.13.32.343000000 PM 1
    
    9 rows
    How can I do? If someone helped me on this subject, I would really appreciate it...
    Kind regards
    Sedef
    SELECT BAGLANTIDATE BAGLANTIDATE, CABONE CABONE
    FROM SEDEF_BILGI
    WHERE CABONE = '1' AND
    BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    union all
    SELECT KAYITDATE, ABONE
    FROM GPRS_TB_SAYACISEMRI
    WHERE ABONE = '1' AND
    KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    

    Ravi Kumar

  • 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

    ---

  • SQL join on the two tables where the column as another column

    Hi all


    tried to get the results of a join between two tables where only one column is like another.

    Table1 (nameA) examples: black2, green1

    Table2 (Name) example: black2.location.uk.com, green1.location.uk.com

    so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!

    My sql up to now:
    select * from  schema.table1 a
    join schema.table2 b 
    on a.nameA like concat('%', b.nameB, '%'); 
    but it errors:

    ORA-00909: invalid number of arguments
    00909 00000 - "invalid number of arguments.

    Any help or advice would be greatly appreciated, thank you!

    Or any of them should do...

    select * from  schema.table1 a
    join schema.table2 b on a.nameA like '%'||b.nameB||'%';
    

    or

    select * from  schema.table1 a
    join schema.table2 b on instr(b.nameB,a.nameA) > 0
    
  • How to join two tables of different schemas of Oracle by using a subquery

    I'm trying to join two different schemas of Oracle tables using a subquery. I can extract data from each of the tables without problem. However, when I combine select statements it by using a subquery I get Oracle error *'ORA-00936: lack of expression ' *. Given that each SELECT statement runs on its own without error I don't understand what's missing. I'm trying to get the result set is matching the LINE_ID of PDTABLE_12_1 in the schema with the table PDTABLE_201 MAT_DESCRIPTION DD_12809 in the RA_12809 schema.

    The query is as follows:

    SQL = "SELECT [DD_12809]. [PDTABLE_12_1]. LINE_ID OF [DD_12809]. [PDTABLE_12_1] JOIN "_".
    + "(SELECT [RA_12809]. [PDTABLE_201]. MAT_DESCRIPTION "_".
    "FROM [RA_12809]. [PDTABLE_201]) AS FAB "_".
    + 'ON [DD_12809]. [PDTABLE_12_1]. PIPING_MATER_CLASS = FAB. PIPING_MATER_CLASS ".

    The format of the request is copied from a manual of programming SQL.

    I also tried running the query uses a right JOIN on the two tables, but got the same results. Any ideas would be useful. Thank you!

    Published by: user11338343 on October 19, 2009 06:55

    The format for the join of two tables in Oracle feels like any other database:

    SELECT a.col1, a.col2, ..., b.col1, b.col2, ...
    FROM   schema1.table1 a,
           JOIN schema2.table2 b ON a.col = b.col and ...
    WHERE  a.other_col = 'FRED'
    AND    ....;
    

    Do not place bracketed identifiers in Oracle. The account that connects to the database must have select privileges on the two tables.

Maybe you are looking for