Sql join without combining all rows

I've searched questions but can't seem to apply to my scenario.  Please see attached code below.  I am trying to join two subsets of this data but am getting duplicates/too many rows please see subsets below main query and main results (i'm hoping
you can understand by providing data/examples without table defs as tables are enormous) (please excuse formatting i don't know how to line everything up in this) :
    IF OBJECT_ID(N'tempdb..#TRANS', N'U') IS NOT NULL
        BEGIN
            DROP TABLE #TRANS;
        END
    DECLARE @Item NVARCHAR(6) = 'AAS682' ,
        @ExpiryDate AS DATETIME = '2015-01-10 00:00:00.000'
    SELECT  ITO.REFERENCEID ,
            WP.PRODID ,
            WP.WMSPALLETID ,
            ITR.ITEMID ,
            ITR.QTY ,
            ITR.STATUSISSUE ,
            ITR.STATUSRECEIPT ,
            ITO.REFERENCECATEGORY ,
            PT.USEBYDATE
    INTO    #TRANS
    FROM    dbo.INVENTTRANS AS ITR
            JOIN INVENTDIM AS ID ON ID.INVENTDIMID = ITR.INVENTDIMID
            JOIN dbo.WMSPALLET AS WP ON WP.WMSPALLETID = ID.WMSPALLETID
            JOIN dbo.PRODTABLE AS PT ON PT.PRODID = WP.PRODID
            JOIN dbo.INVENTTRANSORIGIN AS ITO ON ITR.INVENTTRANSORIGIN = ITO.RECID
    WHERE   ITO.REFERENCECATEGORY IN ( 0, 2, 8 )
            AND PT.USEBYDATE = @ExpiryDate;
    SELECT * FROM #TRANS
Which gives me :
    REFERENCEID PRODID WMSPALLETID ITEMID QTY STATUSISSUE STATUSRECEIPT REFERENCECATEGORY USEBYDATE
    M0000042 M0000042 1288390 BAS242 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000042 M0000042 1288391 BAS242 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000042 M0000042 1288392 BAS242 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000042 M0000042 1288393 BAS242 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000042 M0000042 1288394 BAS242 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000043 M0000043 1288395 BAS243 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000043 M0000043 1288396 BAS243 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000043 M0000043 1288397 BAS243 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000043 M0000043 1288398 BAS243 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000043 M0000043 1288399 BAS243 255.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000044 1288400 AAS682 168.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000044 1288401 AAS682 168.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000044 1288402 AAS682 168.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000044 1288403 AAS682 168.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000044 1288404 AAS682 168.0000000000000000 0 2 2 2015-01-10 00:00:00.000
    M0000044 M0000042 1288390 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288391 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288392 BAS242 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288395 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288396 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288397 BAS243 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    0013949 M0000044 1288400 AAS682 -32.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013949 M0000044 1288402 AAS682 -168.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288400 AAS682 -35.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288401 AAS682 -29.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013952 M0000044 1288400 AAS682 -28.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013953 M0000044 1288400 AAS682 -73.0000000000000000 2 0 0 2015-01-10 00:00:00.000
I want to join these two query result sets
    WITH    ACODE
              AS ( SELECT   *
                   FROM     #TRANS
                   WHERE    ITEMID = @Item
                            AND STATUSISSUE IN ( 1, 2 )
        SELECT  *
        FROM    ACODE
    SELECT  *
    FROM    #TRANS
    WHERE   REFERENCECATEGORY = 8
    REFERENCEID PRODID WMSPALLETID ITEMID QTY STATUSISSUE STATUSRECEIPT REFERENCECATEGORY USEBYDATE
    0013949 M0000044 1288400 AAS682 -32.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013949 M0000044 1288402 AAS682 -168.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288400 AAS682 -35.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288401 AAS682 -29.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013952 M0000044 1288400 AAS682 -28.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013953 M0000044 1288400 AAS682 -73.0000000000000000 2 0 0 2015-01-10 00:00:00.000
with this
    REFERENCEID PRODID WMSPALLETID ITEMID QTY STATUSISSUE STATUSRECEIPT REFERENCECATEGORY USEBYDATE
    M0000044 M0000042 1288390 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288391 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288392 BAS242 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288395 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288396 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288397 BAS243 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
I tried
    SELECT  ACODE.REFERENCEID ,
                ACODE.PRODID ,
                ACODE.WMSPALLETID ,
                ACODE.ITEMID ,
                ACODE.QTY ,
                TRANS.REFERENCEID ,
                TRANS.PRODID ,
                TRANS.WMSPALLETID ,
                TRANS.ITEMID ,
                TRANS.QTY
        FROM    ACODE
                CROSS APPLY ( SELECT    REFERENCEID ,
                                        PRODID ,
                                        WMSPALLETID ,
                                        ITEMID ,
                                        QTY
                              FROM      #TRANS
                              WHERE     ACODE.PRODID != #TRANS.PRODID
                                        AND REFERENCECATEGORY
= 8
                            ) TRANS
but this gave me 6 * 6 36 rows... I want to just bolt the right query on to the end of the left query.  exactly like a union
    SELECT  *
                            FROM    ACODE
                            UNION
                            ( SELECT    *
                              FROM      #TRANS
                              WHERE     REFERENCECATEGORY = 8
    REFERENCEID PRODID WMSPALLETID ITEMID QTY STATUSISSUE STATUSRECEIPT REFERENCECATEGORY USEBYDATE
    0013949 M0000044 1288400 AAS682 -32.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013949 M0000044 1288402 AAS682 -168.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288400 AAS682 -35.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013951 M0000044 1288401 AAS682 -29.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013952 M0000044 1288400 AAS682 -28.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    0013953 M0000044 1288400 AAS682 -73.0000000000000000 2 0 0 2015-01-10 00:00:00.000
    M0000044 M0000042 1288390 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288391 BAS242 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000042 1288392 BAS242 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288395 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288396 BAS243 -255.0000000000000000 2 0 8 2015-01-10 00:00:00.000
    M0000044 M0000043 1288397 BAS243 -50.0000000000000000 2 0 8 2015-01-10 00:00:00.000
except the bottom 6 rows attached to the right of the query... Basically the 'B' items make up the 'A' item.  Which is the purpose of this report, but all the data exists in the same tables which is what i'm really struggling with... thanks!

There's a simple answer to this. If the relationship between the tables does not exist to give you the results you want,
you need to CREATE your own relationship. I used ROW_NUMBER OVER (ORDER BY PALLETID) to give me unique ID's for both datasets. THen simply join ACODEID = BCODEID. (make sure you check different joins to make sure you don't exclude rows from one
side or the other) Simple!

Similar Messages

  • MS SQL - Add column with all rows being "0"

    Add column with all rows being "0"

    nevermind
    "lee" <[email protected]> wrote in message
    news:e3b5kt$mch$[email protected]..
    > Add column with all rows being "0"
    >
    >
    >

  • Export in excel without displaying all rows

    Hello,
    I use OBIEE version 10.1.3.4.1.
    I have a report in "table view" with thousands of rows.
    I would like to export a report to Excel, without displaying the data. Is possible to set the execution as an export in Excel?
    Alternatively I enabled the "Page Control" by 50 "row per page." Is possible to export to excel all the row of the report without to see them all?
    Thanks
    Sara
    Edited by: Sara C. on 25-gen-2010 6.23

    Hi Sara,
    you have 2 options:
    1. use ibots to deliver your report in the form of an excel. This would avoid the generation of report.
    2. Use "download to excel" option. This option downloads the entire content and NOT the ones displayed on the screen.
    Hope this helps.
    cheers,
    Vineeth

  • How can I get the number of rows in my sql result, without a loop?

    Hello,
    I've a problem, I would like to get the number of rows in my sql result without make a loop like :
    while (rs.next()){
    int number = rs.getRow();
    Is there any method to do this, on the first element?
    Thx, STeF

    If you want to count how many rows are in result set, I dont think you can, but you could always run a count statement for that sql
    say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......
    then you can count the rows this statement returns by
    select count(*) from
    (say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......)
    This way you will get the count for just that sql

  • How to force SQL*Loader to assign the same SYSDATE for all rows?

    I want to use SQL*Loader to load some rows and a "SYSDATE" generated column, but making sure this date is THE SAME for all rows. I have seen that if I load HUNDREDS of rows there is a little difference between them (in terms of seconds). I guess it is "the moment each row entered the DB", but I need the same value for all rows (preferably, "the moment SQL*Loader was launched"). Is there any way to achieve this?
    Thank you very much.

    Hello user2393320.
    Given some thought, using a date value to identify all records from a single load isn't very wise.
    Are you able to create a procedure on the database that could be executed during SQL*Loader's execution? If so, you could develop the procedure to take in the record number of the row being loaded as an input parameter and output this unique date value for all rows loaded. The procedure would need to store the date value in a table when the first row is being loaded and return the stored date value as its output. This obviously assumes that only one sqlldr session is running at any time.
    I highly recommend using a numeric sequence in the control file instead of a date to identify each file load:
    , file_load_seq SEQUENCE(MAX, 1)
    Another approach would be to load the record number being loaded in addition to the sysdate:
    , record_number RECNUM
    Hope this helps,
    Luke

  • SQL - Can u print all the dates between two given dates (Without PL/SQL)

    Hi Friends,
    I want to know if u can print all the dates between two given dates without using pl/sql.
    date1,date2 are given
    write a sql statement to display all the dates lying between those two dates.
    An earlier will be appreciated.
    Thanks in Advance
    Sriram
    null

    Sriram,
    Try this....
    select to_date('01-JAN-00')+to_number(rownum)
    from all_tables
    where rownum < to_date('10-JAN-00')-to_date('01-JAN-00')
    TO_DATE('
    02-JAN-00
    03-JAN-00
    04-JAN-00
    05-JAN-00
    06-JAN-00
    07-JAN-00
    08-JAN-00
    09-JAN-00

  • Join all rows bases on one column value

    Hi All,
    I have requrement like Join all rows bases on one column value, i am not getting how to accomplish that. Here is my requrement. i have table test(id,id_desc) with no key
    table:Test
    id id_desc
    1 desc_a
    1 desc_b
    1 desc_c
    Now the requremnet i have one more table as test1(id,id_desc) here id is primary key. where record i need to insert as
    id id_desc
    1 desc_a
    desc_b
    desc_c

    orza wrote:
    Hi All,
    I have requrement like Join all rows bases on one column value, i am not getting how to accomplish that. Here is my requrement. i have table test(id,id_desc) with no key
    table:Test
    id id_desc
    1 desc_a
    1 desc_b
    1 desc_c
    Now the requremnet i have one more table as test1(id,id_desc) here id is primary key. where record i need to insert as
    id id_desc
    1 desc_a
    desc_b
    desc_cI'm guessing you want to pivot the results in TEST and use that to insert into TEST1?
    If so this may be useful
    http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • New airport: can't get my macbook or my imac to join my wireless automatically, my other stuff still joins without problems but i have to join manually with the book and the imac ?? I've tried all the settings and every thing else I can think of.....

    new airport: can't get my macbook or my imac to join my wireless automatically, my other stuff still joins without problems but i have to join manually with the book and the imac ?? I've tried all the settings and every thing else I can think of.....
    Running on Lion, never had a problem before until the old airport died and I replaced it.

    try connecting the device in _*recovery mode*_, then restore from your backup.
    also, make sure [_*Apple Mobile Device Service*_|http://support.apple.com/kb/TS1567] is installed and started.
    JGG

  • Joins And For all Enteries in Select Statement

    Could you please tell me when there is a high amount of data which is being handled in the table, does the use of INNER JOINS and FOR ALL ENTERIES in SELECT Statement decreases the system performance? ?
    Can you also let me know where can i get some tips regarding do's and dont's for ABAP Programming, I want to increase my system performance.
    Currently the programs which are being used are taking a lot of time for execution...
    Its very URGENT!

    Hai Jyotsna
    Go through the following Tips for improving Performence
    For all entries
    The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
    The plus
    Large amount of data
    Mixing processing and reading of data
    Fast internal reprocessing of data
    Fast
    The Minus
    Difficult to program/understand
    Memory could be critical (use FREE or PACKAGE size)
    Some steps that might make FOR ALL ENTRIES more efficient:
    Removing duplicates from the driver table
    Sorting the driver table
    If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
                   FOR ALL ENTRIES IN i_tab
                      WHERE mykey >= i_tab-low and
                 mykey <= i_tab-high.
    Nested selects
    The plus:
    Small amount of data
    Mixing processing and reading of data
    Easy to code - and understand
    The minus:
    Large amount of data
    when mixed processing isn’t needed
    Performance killer no. 1
    Select using JOINS
    The plus
    Very large amount of data
    Similar to Nested selects - when the accesses are planned by the programmer
    In some cases the fastest
    Not so memory critical
    The minus
    Very difficult to program/understand
    Mixing processing and reading of data not possible
    Use the selection criteria
    SELECT * FROM SBOOK.                   
      CHECK: SBOOK-CARRID = 'LH' AND       
                      SBOOK-CONNID = '0400'.        
    ENDSELECT.                             
    SELECT * FROM SBOOK                     
      WHERE CARRID = 'LH' AND               
            CONNID = '0400'.                
    ENDSELECT.                              
    Use the aggregated functions
    C4A = '000'.              
    SELECT * FROM T100        
      WHERE SPRSL = 'D' AND   
            ARBGB = '00'.     
      CHECK: T100-MSGNR > C4A.
      C4A = T100-MSGNR.       
    ENDSELECT.                
    SELECT MAX( MSGNR ) FROM T100 INTO C4A 
    WHERE SPRSL = 'D' AND                
           ARBGB = '00'.                  
    Select with view
    SELECT * FROM DD01L                    
      WHERE DOMNAME LIKE 'CHAR%'           
            AND AS4LOCAL = 'A'.            
      SELECT SINGLE * FROM DD01T           
        WHERE   DOMNAME    = DD01L-DOMNAME 
            AND AS4LOCAL   = 'A'           
            AND AS4VERS    = DD01L-AS4VERS 
            AND DDLANGUAGE = SY-LANGU.     
    ENDSELECT.                             
    SELECT * FROM DD01V                    
    WHERE DOMNAME LIKE 'CHAR%'           
           AND DDLANGUAGE = SY-LANGU.     
    ENDSELECT.                             
    Select with index support
    SELECT * FROM T100            
    WHERE     ARBGB = '00'      
           AND MSGNR = '999'.    
    ENDSELECT.                    
    SELECT * FROM T002.             
      SELECT * FROM T100            
        WHERE     SPRSL = T002-SPRAS
              AND ARBGB = '00'      
              AND MSGNR = '999'.    
      ENDSELECT.                    
    ENDSELECT.                      
    Select … Into table
    REFRESH X006.                 
    SELECT * FROM T006 INTO X006. 
      APPEND X006.                
    ENDSELECT
    SELECT * FROM T006 INTO TABLE X006.
    Select with selection list
    SELECT * FROM DD01L              
      WHERE DOMNAME LIKE 'CHAR%'     
            AND AS4LOCAL = 'A'.      
    ENDSELECT
    SELECT DOMNAME FROM DD01L    
    INTO DD01L-DOMNAME         
    WHERE DOMNAME LIKE 'CHAR%' 
           AND AS4LOCAL = 'A'.  
    ENDSELECT
    Key access to multiple lines
    LOOP AT TAB.          
    CHECK TAB-K = KVAL. 
    ENDLOOP.              
    LOOP AT TAB WHERE K = KVAL.     
    ENDLOOP.                        
    Copying internal tables
    REFRESH TAB_DEST.              
    LOOP AT TAB_SRC INTO TAB_DEST. 
      APPEND TAB_DEST.             
    ENDLOOP.                       
    TAB_DEST[] = TAB_SRC[].
    Modifying a set of lines
    LOOP AT TAB.             
      IF TAB-FLAG IS INITIAL.
        TAB-FLAG = 'X'.      
      ENDIF.                 
      MODIFY TAB.            
    ENDLOOP.                 
    TAB-FLAG = 'X'.                  
    MODIFY TAB TRANSPORTING FLAG     
               WHERE FLAG IS INITIAL.
    Deleting a sequence of lines
    DO 101 TIMES.               
      DELETE TAB_DEST INDEX 450.
    ENDDO.                      
    DELETE TAB_DEST FROM 450 TO 550.
    Linear search vs. binary
    READ TABLE TAB WITH KEY K = 'X'.
    READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
    Comparison of internal tables
    DESCRIBE TABLE: TAB1 LINES L1,      
                    TAB2 LINES L2.      
    IF L1 <> L2.                        
      TAB_DIFFERENT = 'X'.              
    ELSE.                               
      TAB_DIFFERENT = SPACE.            
    LOOP
    AT TAB1.                     
        READ TABLE TAB2 INDEX SY-TABIX. 
        IF TAB1 <> TAB2.                
          TAB_DIFFERENT = 'X'. EXIT.    
        ENDIF.                          
      ENDLOOP.                          
    ENDIF.                              
    IF TAB_DIFFERENT = SPACE.           
    ENDIF.                              
    IF TAB1[] = TAB2[].  
    ENDIF.               
    Modify selected components
    LOOP AT TAB.           
    TAB-DATE = SY-DATUM. 
    MODIFY TAB.          
    ENDLOOP.               
    WA-DATE = SY-DATUM.                    
    LOOP AT TAB.                           
    MODIFY TAB FROM WA TRANSPORTING DATE.
    ENDLOOP.                               
    Appending two internal tables
    LOOP AT TAB_SRC.              
      APPEND TAB_SRC TO TAB_DEST. 
    ENDLOOP
    APPEND LINES OF TAB_SRC TO TAB_DEST.
    Deleting a set of lines
    LOOP AT TAB_DEST WHERE K = KVAL. 
      DELETE TAB_DEST.               
    ENDLOOP
    DELETE TAB_DEST WHERE K = KVAL.
    Tools available in SAP to pin-point a performance problem
    ·                The runtime analysis (SE30)
    ·                SQL Trace (ST05)
    ·                Tips and Tricks tool
    ·                The performance database
    Optimizing the load of the database
    Using table buffering
    Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
    Select DISTINCT
    ORDER BY / GROUP BY / HAVING clause
    Any WHERE clause that contains a sub query or IS NULL expression
    JOIN s
    A SELECT... FOR UPDATE
    If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
    Use the ABAP SORT Clause Instead of ORDER BY
    The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
    If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
    Avoid the SELECT DISTINCT Statement
    As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
    Thanks & regards
    Sreenivasulu P

  • SQL - JOIN using UNION ?? UNION using JOIN ?? with example!

    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword?
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?
    Can you give me an example of how to do this if possible?

    Hi,
    Welcome to the forum!
    user13067794 wrote:
    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?The correct answer to those questions is: Why would you want to? All versions of Oracle (and probably any other database product) provide JOIN to do certain things and UNION to do other things. Why not use those features the way they were designed to be used? Even if it is possible to do what you ask, it's going to be more complicated and less efficient.
    If you really must:
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword? You can select the relevant columns from each table, and NULLs for all the columns from other tables, in a UNION query. Then you can use GROUP BY or analytic functions to combine data from different rows. For example, this JOIN:
    SELECT     d.dname
    ,     e.mgr
    FROM     scott.dept     d
    JOIN     scott.emp     e  ON     d.deptno  = e.deptno
    ;could be written using UNION, but no JOIN, like this:
    WITH     union_data     AS
         SELECT     deptno
         ,     dname
         ,     NULL     AS empno
         ,     NULL     AS mgr
         FROM     scott.dept
        UNION ALL
         SELECT     deptno
         ,     NULL     AS dname
         ,     empno
         ,     mgr
         FROM     scott.emp
    ,     quasi_join     AS
         SELECT     MAX (dname) OVER (PARTITION BY deptno)     AS dname
         ,     mgr
         ,     empno
         FROM     union_data
    SELECT     dname
    ,     mgr
    FROM     quasi_join
    WHERE     empno     IS NOT NULL
    ;Depending on your tables and your requirements, you might be able to do something a little simpler.
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?A FULL OUTER JOIN is similar to UNION.
    This UNION query:
    SELECT     dname          AS txt
    FROM     scott.dept
    UNION
    SELECT     TO_CHAR (mgr)     AS txt
    FROM     scott.emp
    ;Can be written like this, using JOIN but no UNION:
    SELECT DISTINCT
         NVL2 ( e.empno
              , TO_CHAR (e.mgr)
              , d.dname
              )          AS txt
    FROM          scott.dept     d
    FULL OUTER JOIN     scott.emp     e  ON       1 = 2
    user13067794 wrote:I too don't any example as such, but I am thinking on this line -
    Select a.x, b.y
    from a,b
    where a.key=b.key and sal<5000
    UNION
    Select a.x, b.y
    From a,b
    Where a.key=b.key and sal>7000
    can we get same result using JOIN?That's a very special case. You can get the same results without using UNION like this:
    Select distinct
         a.x
    ,      b.y
    from      a
    ,     b
    where      a.key     = b.key
    and      (        sal < 5000
         OR     sal > 7000
    Can we do something similar using UNION without using JOIN keyword??What you posted does not use the JOIN keyword.
    To get the same results without using a join (either with or without the JOIN keyword), you can use UNION together with aggregate or analytic functions, as I showed earlier.
    Edited by: Frank Kulash on Jul 5, 2011 9:01 PM

  • Update all rows in a View Column via one Apex Form field

    Appreciate any helpful answers to this query.
    I have an Apex App (4.x) where I have a view: PRICE_MODEL_CRA_V
    In the view, I have the following applicable columns:
    COUNTRY
    GRADE
    SALARY
    In the form I have the following fields
    :P16_COUNTRY (DROPDOWN)
    :P16_GRADE (DROPDOWN)
    :P16_SALARY (Number)
    In my app, I have a form with an Update button. I am simply trying to get Apex to update all rows in the salaray column in the view, where the country and grade match.
    I've the following code for the Update button:
    UPDATE PRICE_MODEL_CRA_V
    SET SALARY = :P16_SALARY
    WHERE COUNTRY = :P16_COUNTRY
    AND GRADE = :P16_GRADE
    The option I have chosen in condition type is:
    Value of Item / Column expression is NOT Null (as there are values in the column)
    Also tried SQL Expression and it does not like..says that there is No Expression.
    Thanks again if anyone can help :)

    Hi,
    Sorry I realize now that piece of information was not well supported.
    If I choose SQL Expression for Condition Type in my Form Page and I try to Apply Changes
    Apex says this..
    •Failed to parse SQL query!
    ORA-00936: missing expression
    I was assuming that I need to have the colon for the items in the form where I am wanting Apex to grab the values entered by the user. I tried them without the colons with the SQL Expression condition and same result.
    UPDATE PRICE_MODEL_CRA_V
    SET SALARY = P16_SALARY
    WHERE COUNTRY = P16_COUNTRY
    AND GRADE = P16_GRADE
    I did put 1-1/0 in my expression field and applied changes and then tried ot submit the form and it does not produce an error, so perhaps it is not being called? Where would I start with troubleshooting that?
    Thanks,

  • Regular Report Not Returning All Rows

    Greetings,
    On APEX version 4.1.1.00.23 Using latest versions of Chrome and IE. I found some threads that discussed this aspect some, but not to the extent that is helpful to my situation.
    I know it is crazy to have APEX return 40K+ rows on a report, but I have a need to do so. I need to return that many rows from a table so that an APEX page can be opened via Excel and then have an Excel macro run over the report results and import all 40K+ rows into a worksheet. As I said, that's crazy, but the decision isn't mine. :-) We have the macro working and it passes parameters to the APEX page and imports data from the APEX page.
    Also, the report has 14 columns on it, not that many.
    Given the requirement above I have a regular report page that only has the report and 2 page items on it. The page items contain values that are passed via Excel and are then used in the WHERE condition of the report. Using the same WHERE condition, when I run the SQL for the report outside of APEX it returns 46,840 rows. I have the both the Number of Rows and Maximum Row Count settings set to 50000. And, I have the Pagination Scheme set to Row Ranges X to Y of Z (with pagination).
    When I run the page and enter the selection criteria the report only returns 15,500 rows. Yes, that's a lot rows. And, it takes about 5 minutes to populate. But, it doesn't return ALL of the rows. Also, the pagination suggests that all rows were returned because it reads - row(s) 1 to 15500 of 15500. I have changed the pagination and max rows settings a lot to see of it's just a matter of having the correct report setting. I've yet to find a setting that will cause the whole 46840 result set to be returned.
    It may end up that the report selection needs to change in order to return fewer rows. But, regardless of that why isn't APEX returning the complete result set now? And, is there a way to force it to return the complete result set regardless of the size?
    Any suggestions are appreciated.
    Thanks, Tony

    cloaked wrote:
    Thanks for the response. Yup, you're correct. Downloading to a CSV might be better. I've set reports up that way many, many times. I have even developed pages that import from a CSV into APEX using PL/SQL, years before it was an APEX feature. I initially set the report up to allow it to be downloaded, but the user doesn't want it to work that way.
    The worksheet will be used by a lot of people in our accounting department and they want the process to be as simple as possible. Right now Excel opens up the APEX page, logs into the application, passes parameters to it for the month and company, hits the Select button, waits on the report to build, then automatically imports it, and finally closes the page. It is quite slick. Yes, it takes 5 minutes to run, but the user is OK with that given what the automation provides.
    So, in order for the automated import to work properly all 45K rows need to display on one page, without pagination. I currently have pagination on the page simply to determine if APEX is returning all of the rows.A process of this nature might work better using an export: XML or export: CSV report template, which won't go anywhere near pagination. When a page containing a report using these templates is requested APEX sends the report results in XML or CSV format rather than rendering the page. This should be faster, avoid complications with pagination, and be easier to parse in Excel.
    Previous thread along similar lines: +{thread:id=2285213}+

  • Loop Not Returning All Rows

    I finally need to turn to the forum after trying for a few days to resolve my problem I decide to turn to the Oracle people for help.
    The following code below does two things:
    1. If I have the get_menu_label in side of it's own loop it never returns
    2. If I take the get_menu_label out side of it's own loop it returns but does not return all the data.
    DECLARE
    -- GETTING THE DATABASE NAME
    CURSOR get_db_name
    IS
    SELECT DATABASE
    FROM uaf_mfgp_menus_and_groups_vm
    GROUP BY DATABASE
    ORDER BY DATABASE ASC;
    -- GETTING THE OBJECT_ID FOR EACH DATABASE
    CURSOR get_object_id_db (l_db_name VARCHAR2)
    IS
    SELECT object_id
    FROM UAF_FORM_OBJECTS
    WHERE object_label_2 = l_db_name;
    -- GETTING THE GROUP NAME
    CURSOR get_gp_name
    IS
    SELECT group_name
    FROM uaf_mfgp_menus_and_groups_vm
    GROUP BY group_name
    ORDER BY group_name ASC;
    -- GETTING THE OBJECT_ID FOR GROUP WITH GP NAME AND DATABASE
    CURSOR get_object_id_gp (l_gp_name VARCHAR2, db_id NUMBER)
    IS
    SELECT object_id
    FROM UAF_FORM_OBJECTS
    WHERE object_label_2 = l_gp_name AND parent_object_id = db_id;
    -- GETTING MENU LABEL
    CURSOR get_menu_label (l_db_name VARCHAR2, l_gp_name VARCHAR2)
    IS
    SELECT menu_label
    FROM uaf_mfgp_menus_and_groups_vm
    WHERE DATABASE = l_db_name AND group_name = l_gp_name;
    got_object_id_db NUMBER (20);
    got_object_id_gp NUMBER (20);
    got_db VARCHAR2 (100);
    got_menu_label VARCHAR2 (200);
    BEGIN
    FOR c1 IN get_db_name
    LOOP
    FOR c2 IN get_gp_name
    LOOP
    OPEN get_object_id_db (c1.DATABASE);
    FETCH get_object_id_db
    INTO got_object_id_db;
    OPEN get_object_id_gp (c2.group_name, got_object_id_db);
    FETCH get_object_id_gp
    INTO got_object_id_gp;
              CLOSE get_object_id_db;
    CLOSE get_object_id_gp;
    OPEN get_menu_label (c1.DATABASE, c2.group_name);
    LOOP
    FETCH get_menu_label
    INTO got_menu_label;
    END LOOP;
    CLOSE get_menu_label;
    DBMS_OUTPUT.put_line ( 'GP_OBJECT_ID= '
    || got_object_id_gp
    || ' '
    || 'MENU_LABEL= '
    || got_menu_label
    END LOOP;
    END LOOP;
    END;
    /

    Javier, this the wrong way to use PL/SQL. Oracle SQL can do all this for you using JOINs.
    This code, even if it did work, would be terrible slow - unable to scale with data volumes.
    This code breaks a few fundamental Oracle rules:
    - row-by-row processing using PL/SQL
    - huge number of context swicthes per PL/SQL loop iteration
    - not maximizing SQL and minimizing PL/SQL
    I suggest you trash this code and write a SQL JOIN instead.

  • How to Update All Rows in ViewObjectImpl

    I have a SQL based VO with three attributes where two attributes are from SQL, and one is transient.
    The SQL returns,
    1, deptA
    2, deptB
    3, deptC
    4, deptD
    I need to populate the third attribute separately. Say I have a Java class that will give me,
    2, Dallas
    3, Chicago
    I want to be able to display in table form,
    1, deptA, null
    2, deptB, Dallas
    3, deptC, Chicago
    4, deptD, null
    I know I can do this in VORowImpl, where for each row, get my Java class, match the ID, and set the third attribute. But I am trying to avoid fetching all the cities again and again for each row. So instead, I tried fetching the cities only once in VOImpl, then in createRowFromResultSet, set the third attribute before returning. This works the way I want except for one problem. I noticed say if the SQL returns four rows, createRowFromResultSet is only called three times. The first row never passes through createRowFromResultSet. So I am able to set the third attribute correctly except for the first row.
    Any suggestions? Thanks.

    The extra information for the third attribute is not available in the database. It can only come from the Java class. So a SQL join was not possible.
    The view link approach worked for me. I created SQL based VO1 and Java based VO2 and linked them. Then added transient attributes on VO1 and used Groovy to pull the value from VO2.
    Thanks for all the input.

  • XML-SQL  multiple SQL_QUERY to sing row instances..

    Hello,
    Is it possible to run multiple querys and return them all to a structure like this..
    <HEADER_SELECTS>
       <row>
           <select results1></select results1>
       </row>
       <row>
           <select results2></select results2>
       </row>
    </HEADER_SELECTS>
    I have tried several data type structures, but all of them execute only the first "access" SQL_QUERY option.

    Hi Tom,
    A suggestion : you could go for SQL joins.
    Concerbed weblog is:
    https://www.sdn.sap.com/sdn/weblogs.sdn?blog=/pub/wlg/1725 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    hope this helps.
    Regards,
    Priyanka

Maybe you are looking for

  • Syntax error in start routine

    Dear All, I have activated the infocube 0sd_c03 with grouping "in data flow before" and the infocube is activated with datasources 2LIS_11_VAITM 2LIS_11_VAHDR 2LIS_12_VCITM 2LIS_12_VCHDR 2LIS_13_VDITM 2LIS_13_VDHDR in 3.x where as TRCS 2LIS_13_VDITM

  • Report for PO status

    Hello Experts , Can you tell me the standard report for the status of PO as in GR qty , value , in voiced qty & value etc & open qty & value ?? Regards

  • Adobe Output Module install on MacBook Pro running OS X

    I have tried to install the Adobe Output Module but it is not working. I see the "Output" option in Bridge but when clicked nothing happens. I followed the instructions provided with the download. I think my issue might be where i am placing the "Ado

  • Problem removing bundles from group with ZLMAN

    I am having trouble removing a bundle from a bundlegroup with the zlman utility. The syntax I am using seems correct and the groups and bundle name are also. Here is the command and it's output from the command with the debug option: (if I use a bogu

  • Making a video or playing videos is not possible

    I have a Problem with my camara on i phone 4 it is not possible to make videos or play videos, taken before. problems also with youtube app. thx for help