Help Reqd in SQL

Hi Friends,
This may be a dumb question but please bear with me I am not a SQL person.
I want to pull all records of table A and matched records of table B. Is following syntax correct:
SELECT
TABLE1.FIELDA
TABLE2.FIELDB
FROM
TABLE1 LEFT JOIN
TABLE2 ON (TABLE1.FIELDA = TABLE2.FIELDA)

Hi Friends,
This may be a dumb question but please bear with me I
am not a SQL person.
I want to pull all records of table A and matched
records of table B. Is following syntax correct:
SELECT
TABLE1.FIELDA
TABLE2.FIELDB
FROM
TABLE1 LEFT JOIN
TABLE2 ON (TABLE1.FIELDA = TABLE2.FIELDA)Depends what you mean by "matched" records.
If you only want those that match then you don't want the "LEFT" in the join.
If you want everything from TABLE1 even if there isn't a matching record in TABLE2 then your query will give you that.

Similar Messages

  • Help Reqd in SQL Syntax

    Hi,
    I am using the following statement:
    select * from table1 where field1 = 'a' and rownum <= 10;
    After I execute this statement SQL Plus gets stuck,
    I am not able to figure out what I am doing wrong here,
    Please advice,
    Thanks,
    Raja

    Alright you may have to CTRL+C that thing. Anyway, here is a very simple example of how explain plan works:
    SQL*Plus: Release 10.2.0.2.0 - Production on Mon May 12 10:51:46 2008
    Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> explain plan for select * from dual;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3543395131
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    8 rows selected.
    SQL>

  • Error in MIRO Help Reqd

    I have setup new instance. Created p.o & done MIGO things worked fine. In MIRO typically error is seen in tax code. I have assigned Tax procedure TAXGB to country IN. In Fin Acct in tax on sales & purchases defined new taxcode VX with country option IN. Still during MIRO its showing error Tax code VN & Country IN doesnot exist in procedure TAXGB. In error msg its M8 249 & origin is shown as check invoice document.
    Help reqd from SAP Gurus pls.
    Regards

    Check these links
    while doing MIRO, i am getting error:-Tax code V0 country IN does not exist
    Tax code Z4 country IN does not exist in procedure TAXINJ
    Tax code V0 country IN does not exist in procedure TAXINN
    Tax code V0 country IN does not exist in procedure TAXINN

  • Help Needed in SQL QPAC

    Hi there,
    I need some help regarding the SQL QPAC which is a built in QPAC in Adobe Livecycle Workflow. The SQL QPAC takes MYSQL as the default database. Suppose if we need to connect to the SQL Server or any other database, what is the procedure to do that.
    Suraj

    Hi Suraj
    You need to deploy a second copy of the SQL QPAC, and point it at a different datasource. The datasource is defined as a deployment parameter (it will prompt you when you deploy the new version of the qpac).
    You will also need to define the datasource in your application server. This is done in different ways for different application servers - for details, please see: standards_based_qpacs.pdf (part of the Workflow SDK), page 12, "Creating a JNDI datasource".
    Alternately, you can try out our SQLPlus QPAC. This allows you to directly specify connection url, driver, username and password. The SQLPlus QPAC does a lot of other things that the regular SQL QPAC doesn't do, such as handling multiple rows, testing your query, and outputting the data in a variety of ways.
    Details at: http://www.avoka.com/avoka/qpac_library.shtml
    Howard

  • Urgent Help Reqd: Delta Problem....!!!

    Hi Experts,
    Urgent help reqd regarding follwoing scenario:
    I am getting delta to ODS 1 (infosource : 2LIS_12_VCHDR) from R/3. Now this ODS1 gives delta to Cube1. I got one error record which fails when going to cube (due to master data check).And this record would be edited later.
    So I thought of re loading cube and using error handling to split request in PSA and load valid records in cube.Later when I have coorect info abt error, I would load erroneous record manually using PSA.
    I did following steps:
    1)Failed request is not in cube...(setting is PSA and then into target)....also it has been deleted from PSA.
    2)Remove data status from source ODS1.
    3)Change error handling in infopackage to valid " Valid records update, reporting possible".
    4)start loading of cube.
    But when I did this I got following message :
    <b> "Last delta update is not yet completed.Therefore, no new delta update is possible.You can start the request again if the last delta request is red or green in the monitor"</b>
    But both my requests in cube and ODS are Green...no request is in yellow...!!
    Now the problem is :
    1) I have lost ODS data mart status
    2)how to load valid records to cube, since errorneous record can be edited only after 3- 4 days.
    3)How not to affect delta load of tomorrow.
    Please guide and help me in this.
    Thanks in advance and rest assured I will award points to say thanks to SDNers..
    Regards,
    Sorabh
    Message was edited by: sorabh arora

    Hi Joseph,
    Thanks for replying....
    I apolgize and I have modified the message above..
    I just checked in cube...there is no failed request for today...and neither in PSA....Person who has handed this to me may have deleted this is PSA..and why req is not in failed state in cube...I am not sure..though setting is "PSA and then into data package".....
    So how to go frm here....
    Thanks
    Sorabh

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Help: APEX - PL/SQL Function

    Hello,
    i need some help with a SQL statement.
    I have the follwing Table "TABF":
    ID Number,
    B_Number varchar2(10),
    G_Type varchar2(10),
    Site varchar2(50),
    Event varchar2(50),
    Date varchar(10),
    Dataset varchar2(50),
    Mode varchar2(50),
    Topic varchar2(10),
    Parameter varchar2(10),
    Value varchar2(10)The table is filled with records which, like this:
    B Number | G-Type |Site       |Event  |Date     | Dataset   | Mode    | Topic    | Parameter | Value
    800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 73,9015 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,6951 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,71 
    800257   |   4.2  |  USA      | Test  |18.08.08 | Post      |MBA      | Field    | F_C       | 73,7526 
    800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 4,5170 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,6074 
    800257   |   4.2  |  England  | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,62 
    800257   |   4.2  |  England  | Test  |18.08.08 | Post      |MBA      | Field    | F_H       | 24,4717  Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
    If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
    Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
    And so on.....
    The result should look like this for the example above:
    B Number | G-Type |  Site     |Event  |Date     | Dataset   | Mode    | Topic    |Parameter   | Value    | Topic2   |  Parameter2  | Value2
    800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 73,9015  | -        | -            | -
    800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,6951  | Field    | F_H          | 24,6074
    800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,71    | Field    | F_H          | 24,62 
    800257   |    4.2 |  USA      | Test  |18.08.08 | Post      | MBA     | Field    | F_C        | 73,7526  | -        | -            | -
    800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 4,5170   | -        | -            | -
    800257   |    4.2 |  England  | Test  |18.08.08 | Post      | MBA     | Field    | F_H        | 24,4717  | -        | -            | -Hope you understand my problem and some1 can help me.
    Thank you
    Regards
    Chris
    Edited by: user11369135 on 09.07.2009 00:50

    user11369135 wrote:
    Hello,
    i need some help with a SQL statement.
    I have the follwing Table "TABF":
    Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
    If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
    Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
    And so on.....
    Edited by: user11369135 on 09.07.2009 00:50if I understand correctly then you want a simple GROUP BY on B_number, Event, Date and Dataset.
    But you want additionaly show 3 columns from one of the rows that was grouped.
    This can be done using the little known KEEP syntax.
    Documentation: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#sthref1389
    Example from the docs
    Aggregate Example
    The following example returns, within each department of the sample table hr.employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:
    SELECT department_id,
    MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
    MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
       FROM employees
       GROUP BY department_id;
    DEPARTMENT_ID      Worst       Best
               10       4400       4400
               20       6000      13000
               30       2500      11000
               40       6500       6500
               50       2100       8200
               60       4200       9000
               70      10000      10000
               80       6100      14000
               90      17000      24000
              100       6900      12000
              110       8300      12000
                        7000       7000

  • Help on java.sql.Types class

    Hai Friends ,
    I want some help on java.sql.Types class .
    What is the use of the above class ?
    Some details about this class.

    Good Morning Yekesa
    First of all i would like to thank U for looking into my problem.
    I am using java.sql.Types.OTHER for
    {"?=CALL(storedprocedurename.functionname(?))"}
    registerOutParameter(1,javal.sql.Types.OTHER)
    setString(2,"user")
    here the
    second parameter passes an argument to function name ( viz. username say "user")
    and the function will return the ref cursor as follows:
    // declaration in pl/sql procedure
    begin
    rc ref cursor
    open rc for select * from ss_user where login_name="user";
    return rc;
    end
    now the stored procedure has a return value (i.e. stored function) which it needs to register as
    registerOutParameter(1,javal.sql.Types.OTHER)
    and it finally results in the following errors :
    Loading driver
    Before conn stmt
    After conn stmt
    Calling Stored procedure
    Stored procedure called
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:243)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:2487)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:64)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:54)
    at sptest.<init>(sptest.java:28)
    at sptest.main(sptest.java:49)
    T couldn't understand why it is saying Invalid Column Type because its working fine with both
    java.sql.Types.INTEGER
    and
    java.sql.Types.VARCHAR
    Pl help me at the earliest as i have wasted a lot of time on it.
    pl mail me in detail at [email protected]
    bye then
    bansi
    null

  • Help in designing SQL

    Hi All,
    I need little help in designing SQL. My input and output data is given below:
    Input
    Key
    Date_1
    Date_2
    Key1
    2/14/2011 5:22:35 PM
    2/22/2011 3:05:13 PM
    Key1
    2/24/2011 1:48:07 PM
    5/24/2011 4:50:16 PM
    Key1
    2/24/2011 1:48:59 PM
    4/25/2011 3:36:19 PM
    Key1
    5/24/2011 5:18:19 PM
    6/16/2011 3:17:40 PM
    Key1
    6/16/2011 3:25:42 PM
    6/24/2011 1:33:13 PM
    Key1
    6/17/2011 1:12:54 PM
    6/25/2011 5:55:55 PM
    Output
    Key
    Date_1
    Date_2
    Key1
    2/14/2011 5:22:35 PM
    2/22/2011 3:05:13 PM
    Key1
    2/24/2011 1:48:07 PM
    5/24/2011 4:50:16 PM
    Key1
    5/24/2011 5:18:19 PM
    6/16/2011 3:17:40 PM
    Key1
    6/16/2011 3:25:42 PM
    6/25/2011 5:55:55 PM
    Here out of 2nd and third record of input, output is 2nd record of output and 5th and 6th record of input would come out as  4th record of output. Basically, if we overlapping duration between Date_1 and Date_2, we need to take min of Date_1 and max of Date_2 for that overlapping records. In case of no overlapping, we would simply output input record like  record 1 and 4 of input.
    Out of
    Key1
    2/24/2011 1:48:07 PM
    5/24/2011 4:50:16 PM
    Key1
    2/24/2011 1:48:59 PM
    4/25/2011 3:36:19 PM
    2/24/2011 1:48:07 PM was  min of above 2 and 5/24/20114:50:16 was max of above 2.
    Similarly in other overlapping scenario:
    Key1
    6/16/2011 3:25:42 PM
    6/24/2011 1:33:13 PM
    Key1
    6/17/2011 1:12:54 PM
    6/25/2011 5:55:55 PM
    6/16/2011 3:25:42 PM  was min of above 2 and 6/25/2011 5:55:55 PM was max of above 2.
    Pls help.
    Thanks.

    Hi Frank.,
    The above logic with NVL is not working.
    My input sample is:
    Key
    Date_1
    Date_2
    Key1
    2/14/2011 5:22:35 PM
    2/22/2011 3:05:13 PM
    Key1
    2/24/2011 1:48:07 PM
    5/24/2011 4:50:16 PM
    Key1
    2/24/2011 1:48:59 PM
    Key1
    5/24/2011 5:18:19 PM
    6/16/2011 3:17:40 PM
    Key1
    6/16/2011 3:25:42 PM
    6/24/2011 1:33:13 PM
    Key1
    6/17/2011 1:12:54 PM
    6/25/2011 5:55:55 PM
    I am giving create and insert statement below for creation of above data. Please see if you can help me:
    CREATE TABLE test1
      KEY1          NUMBER     ,   
      DATE_1               DATE ,          
      date_2              DATE
    insert into test1
    values(1, TO_TIMESTAMP ('2/14/2011 5:22:35 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('2/22/2011 3:05:13 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
    values(1, TO_TIMESTAMP ('2/24/2011 1:48:07 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('5/24/2011 4:50:16 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
    values(1, TO_TIMESTAMP ('2/24/2011 1:48:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), '' ) ;
    values(1, TO_TIMESTAMP ('5/24/2011 5:18:19 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/16/2011 3:17:40 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
    values(1, TO_TIMESTAMP ('6/16/2011 3:25:42 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/24/2011 1:33:13 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
    values(1, TO_TIMESTAMP ('6/17/2011 1:12:54 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/25/2011 5:55:55 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
    commit;
    Expected output would be:
    Output
    Key
    Date_1
    Date_2
    Key1
    2/14/2011 5:22:35 PM
    2/22/2011 3:05:13 PM
    Key1
    2/24/2011 1:48:07 PM
    Key1
    5/24/2011 5:18:19 PM
    6/16/2011 3:17:40 PM
    Key1
    6/16/2011 3:25:42 PM
    6/25/2011 5:55:55 PM
    Thanks....

  • Sql query - help reqd

    Hi,
    I require help for sql query. The query will be like
    "SELECT * FROM XYZ WHERE TEXT = 'h*s' "
    and the results will be come like
    “his”
    “homes”
    “houses”
    “horses”,
    “horticulturalists”
    “herbaceous”.
    Thanks,
    Kapil

    Hello,
    SELECT   *
      FROM   XYZ
    WHERE   TEXT LIKE ('h%s');Regards
    Edited by: OrionNet on Feb 2, 2009 12:33 AM

  • SQL Help Reqd.

    Hi All,
    I have following requirement:
    Table Name: CUSTOMER
    Fields in this table: CUSTOMER_ID, TAG, SUBFIELD, VALUE
    When TAG = '100' and SUBFIELD = 'a' VALUE represents Customer created date.
    When TAG = '200' and SUBFIELD = 'a' VALUE represents Customer changed date.
    When TAG = '300' and SUBFIELD = 'a' VALUE represents Customer birth date.
    When TAG = '400' and SUBFIELD = 'a' VALUE represents Customer zip code.
    Table Name: CUSTOMER2
    Fields in this table: CUSTOMER_ID, FIRST_NAME, LAST_NAME
    Now I want all the CUSTOMER_ID whose created date >= Todays date and changed date >= Todays date.
    For all the above CUSTOMER_ID I want to retrieve CUSTOMER2-FIRST_NAME, CUSTOMER2-LAST_NAME, birth date and zip code in a CSV file.
    Can some one please help me with the SQL Code for the above logic,
    Thanks in advance,
    Raja

    Example...
    Without the max and group by...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as cust_id, 'x' as category, 10 as value from dual union all
      2             select 1, 'y', 20 from dual union all
      3             select 1, 'z', 30 from dual union all
      4             select 2, 'x', 40 from dual union all
      5             select 2, 'y', 50 from dual union all
      6             select 2, 'z', 60 from dual)
      7  -- END OF TEST DATA
      8  select cust_id
      9        ,case when category = 'x' then value else null end as x
    10        ,case when category = 'y' then value else null end as y
    11        ,case when category = 'z' then value else null end as z
    12  from t
    13* order by cust_id, x, y, z
    SQL> /
       CUST_ID          X          Y          Z
             1         10
             1                    20
             1                               30
             2         40
             2                    50
             2                               60
    6 rows selected.As you can see the data has been put in the right columns but it's still split into individual rows.
    So using the max and group by we can get all the data on one row for each cust_id...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as cust_id, 'x' as category, 10 as value from dual union all
      2             select 1, 'y', 20 from dual union all
      3             select 1, 'z', 30 from dual union all
      4             select 2, 'x', 40 from dual union all
      5             select 2, 'y', 50 from dual union all
      6             select 2, 'z', 60 from dual)
      7  -- END OF TEST DATA
      8  select cust_id
      9        ,max(case when category = 'x' then value else null end) as x
    10        ,max(case when category = 'y' then value else null end) as y
    11        ,max(case when category = 'z' then value else null end) as z
    12  from t
    13  group by cust_id
    14* order by cust_id
    SQL> /
       CUST_ID          X          Y          Z
             1         10         20         30
             2         40         50         60
    SQL>;)

  • Sql query - help reqd (new)

    Hi,
    I have follwing dataset
    "herb with garden"
    "garden without herb"
    "herb with zbc"
    "garden with pqr"
    Now i want sql query like
    select * from table where text1 = "herb and garden"
    This should populate
    herb with garden
    garden without herb
    And
    select * from table where text1 = "herb or garden"
    This should populate
    "herb with garden"
    "garden without herb"
    "herb with zbc"
    "garden with pqr"

    SQL> with t
      2  as
      3  (
      4     select 'herb with garden' str from dual union all
      5     select 'garden without herb' str from dual union all
      6     select 'herb with zbc' str from dual union all
      7     select 'garden with pqr' str from dual
      8  )
      9  select *
    10    from t
    11   where lower(str) like '%herb%'
    12     and lower(str) like '%garden%'
    13  /
    STR
    herb with garden
    garden without herb
    SQL> with t
      2  as
      3  (
      4     select 'herb with garden' str from dual union all
      5     select 'garden without herb' str from dual union all
      6     select 'herb with zbc' str from dual union all
      7     select 'garden with pqr' str from dual
      8  )
      9  select *
    10    from t
    11   where lower(str) like '%herb%'
    12     or lower(str) like '%garden%'
    13  /
    STR
    herb with garden
    garden without herb
    herb with zbc
    garden with pqr

  • Help Reqd - on simple sql query

    Hi,
    I have two tables back_temp_ord_hist, temp_ord_hist of similar structures
    create table <table_name>
    order_number          varchar2(10),
    item_number          integer,
    sched_line_number          integer,
    dlv_doc_id               varchar2(10),
    mtrl_mstr_key          integer,
    cust_key               integer,
    wrhse_key               integer,
    sls_ord_type          varchar2(4)
    Now I have inserted same data set in the two tables. (same following three rows in both the tables)
    0009032022     160          2     0091383073          27219     1694     20 ZISO
    0009032022     160          3     0091383073          27219     1694     20 ZISO
    0009032022     160          4     0091383073          27219     1694     20 ZISO
    Then I am trying to use a query like below :
         select
              fact.order_number
              , fact.item_number
              , fact.sched_line_number
              , bk_fact.sched_line_number          as old_sched_line_number     
              , fact.dlv_doc_id
              ,dbms_utility.get_hash_value(fact.order_number||fact.item_number||fact.sched_line_number||fact.dlv_doc_id,1,100) ord_hist_hash
              ,dbms_utility.get_hash_value(bk_fact.order_number||bk_fact.item_number||bk_fact.sched_line_number||bk_fact.dlv_doc_id,1,100) back_ord_hist_hash
              , fact.mtrl_mstr_key
              , bk_fact.mtrl_mstr_key           as old_mtrl_mstr_key
              , fact.cust_key
              , bk_fact.cust_key                as old_cust_key
              , fact.wrhse_key
              , bk_fact.wrhse_key                as old_wrhse_key     
              , fact.sls_ord_type
              , bk_fact.sls_ord_type                as old_sls_ord_type
         from      
              temp_ord_hist fact
         join
         back_temp_ord_hist bk_fact
                   on fact.order_number = bk_fact.order_number
                   and fact.item_number = bk_fact.item_number
                   and fact.sched_line_number <> bk_fact.sched_line_number
                   and fact.dlv_doc_id = bk_fact.dlv_doc_id
                   order by ord_hist_hash, back_ord_hist_hash
    But it is actually it is showing 6 rows. But ideally I want no rows as temp_ord_hist.sched_line_number = back_temp_ord_hist.sched_line_number in all the cases over here.
    Practically it can be different then I want those rows but when it is same why the output is showing 6 rows.
    What I am doing wrong over here?
    Regards,
    Koushik

    Not sure how you are getting 6 rows as the output. I did exactly the same thing that you did and I am getting the only 3 rows as the output:
    see below:
    SQL> create table temp_ord_hist
    2 (
    3 order_number varchar2(10),
    4 item_number integer,
    5 sched_line_number integer,
    6 dlv_doc_id varchar2(10),
    7 mtrl_mstr_key integer,
    8 cust_key integer,
    9 wrhse_key integer,
    10 sls_ord_type varchar2(4)
    11 );
    Table created.
    SQL> create table back_temp_ord_hist
    2 (
    3 order_number varchar2(10),
    4 item_number integer,
    5 sched_line_number integer,
    6 dlv_doc_id varchar2(10),
    7 mtrl_mstr_key integer,
    8 cust_key integer,
    9 wrhse_key integer,
    10 sls_ord_type varchar2(4)
    11 );
    Table created.
    SQL> insert into temp_ord_hist values ('0009032022',160,2,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL> insert into temp_ord_hist values ('0009032022',160,3,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL>
    SQL> insert into temp_ord_hist values ('0009032022',160,4,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL> insert into back_temp_ord_hist values ('0009032022',160,2,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL> insert into back_temp_ord_hist values ('0009032022',160,3,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL> insert into back_temp_ord_hist values ('0009032022',160,4,'0091383073',27219,1694,20,'ZISO');
    1 row created.
    SQL> select
    2 fact.order_number
    3 , fact.item_number
    4 , fact.sched_line_number
    5 , bk_fact.sched_line_number as old_sched_line_number
    6 , fact.dlv_doc_id
    7 ,dbms_utility.get_hash_value(fact.order_number||fact.item_number||fact.sched_line_number||fact.dlv_doc_id,1,100) ord_hist_hash
    8 ,dbms_utility.get_hash_value(bk_fact.order_number||bk_fact.item_number||bk_fact.sched_line_number||bk_fact.dlv_doc_id,1,100) back_ord_hist_hash
    9 , fact.mtrl_mstr_key
    10 , bk_fact.mtrl_mstr_key as old_mtrl_mstr_key
    11 , fact.cust_key
    12 , bk_fact.cust_key as old_cust_key
    13 , fact.wrhse_key
    14 , bk_fact.wrhse_key as old_wrhse_key
    15 , fact.sls_ord_type
    16 , bk_fact.sls_ord_type as old_sls_ord_type
    17 from
    18 temp_ord_hist fact
    19 join
    20 back_temp_ord_hist bk_fact
    21 on fact.order_number = bk_fact.order_number
    22 and fact.item_number = bk_fact.item_number
    23 and fact.sched_line_number = bk_fact.sched_line_number
    24 and fact.dlv_doc_id = bk_fact.dlv_doc_id
    25 order by ord_hist_hash, back_ord_hist_hash
    26
    SQL> /
    0009032022 160 3 3 0091383073 4 4 27219 27219 1694 1694 20 20 ZISO ZISO
    0009032022 160 4 4 0091383073 55 55 27219 27219 1694 1694 20 20 ZISO ZISO
    0009032022 160 2 2 0091383073 100 100 27219 27219 1694 1694 20 20 ZISO ZISO
    SQL>

  • Simple SQL Query  - Help Reqd

    Table name: xyz
    Column1 Column2
    x 1
    x 2
    x 3
    x 7
    y 1
    y 3
    y 6
    z 4
    z 2
    z 0
    I want a query to output all Column1 only if Column2 value not in (1,2,3) - all inclusive. In the above example, I want y & z in the output.

    I may be wrong but I think the OP is asking for something more like:
    [email protected](161)> select * from xyz;
    C    COLUMN2
    x          1
    x          2
    x          3
    x          7
    y          1
    y          3
    y          6
    z          4
    z          2
    z          0
    10 rows selected.
    [email protected](161)> select column1
      2  from xyz
      3  minus
      4  select column1
      5  from xyz
      6  where column2 in (1, 2, 3)
      7  group by column1
      8  having count(distinct column2) = 3
      9  /
    C
    y
    zI.e., values from column1 which don't have ALL of (1, 2, 3) in column2.
    cheers,
    Anthony

  • Help needed for SQL query

    hello ,
    I am a beginner in terms of writing sql queries. I hope some body can help me out.
    I have two tables
    mysql> desc user_group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | userAccountId | char(8) | | PRI | | |
    | groupId | char(8) | | PRI | | |
    ---------------------------------------------------+
    2 rows in set (0.00 sec)
    mysql> desc group_t;
    ---------------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    ---------------------------------------------------+
    | id | char(8) | | PRI | | |
    | name | char(50) | YES | | NULL | |
    | email | char(100) | YES | | NULL | |
    | description | char(254) | YES | | NULL | |
    | parentId | char(8) | YES | | NULL | |
    | creatorId | char(8) | YES | | NULL | |
    | createDate | char(20) | YES | | NULL | |
    | updateDate | char(20) | YES | | NULL | |
    | updatorId | char(8) | YES | | NULL | |
    ---------------------------------------------------+
    9 rows in set (0.00 sec)
    what I want is list of all groups with id,name and #of members(which is the # of rows in the user_group_t for any given id). Importantly I need the groups with 0 members also to be listed. In short my output should contain exactly the same number of rows as in group_t table with an additional column indicating # of members for that group.
    Any help would be greatly appreciated.
    Thanks in Advance.
    -Vasanth

    Thanks Donald,
    Actually I figured it out, with the following query:
    select id,name,sum(if(groupid is not null,1,0)) as members from group_t left join user_group_t on id=groupid group by id;
    I tried your solution, but mysql says there is an error at '+' . Anyway I modified your solution to the one below and it worked.
    select a.id, a.name, count(b.groupid) from group_t a left join user_group_t b on a.id=b.groupid group by a.id, a.name;
    I tried that before but then I used Count(*) instead of count on groupid. Your solution is elagant and I will go with yours.
    Thanks again.
    Vasanth

Maybe you are looking for

  • Media Encoder CC exporting the wrong resolution in custom preset h.264

    I have two custom presets in Media Encoder CC.  The original file is an mov Lossless 720x480 from After Effects.  One is h.264 mp4 720x480 and the other is h.264 640x480.  When I encode the resolutions are 872x480 and 581x480 respectively.  Not sure

  • Problm with 'notepad' code..image of the buttons not displayed..help.. ;-(

    I have a source code for developing a notepad but the problem is that when i run it the buttons which i've used as shortcuts don't have there photos displayed on them... they just come across as a rectangular button rather than a cut or a copy photo.

  • HT1338 how to update my ipad

    I likt to update my ipad from 4.2 to 5.1

  • Field Selection for Maintenance Planing

    Hi Dear,            I have done some field selection somewhere in SAP System.Now when I am creating Maintenance Item,Maintenance Plan,now I am getting Function Location field as Required. I don't remember where is the field selection for making the f

  • Error adding new itemWarehouseInfo

    I am trying to add a new warehouse to selected items via DTW. The error I am getting is "Update Failed-Feld cannot be updated [ODBC-1029] Application-defined or object-defined error" Also on some items I am getting "Microsoft SQL Native Client - Viol