How to join the two queries

select itm.inventory_item_id "Item#",itm.segment1,itm.description,qty.SUBINVENTORY_CODE as SHI,
sum(qty.primary_transaction_quantity) "On Hand Qty"
from MTL_ONHAND_QUANTITIES_DETAIL qty,
mtl_system_items itm
WHERE itm.inventory_item_id=qty.inventory_item_id
and itm.ORGANIZATION_ID=qty.ORGANIZATION_ID
and qty.SUBINVENTORY_CODE IN ('ITC-8888', 'ITC-9999')
and trunc(qty.last_update_date) <=:P_DATE_FROM
AND trunc(SYSDATE) >=:P_DATE_TO
group by qty.SUBINVENTORY_CODE,itm.inventory_item_id,itm.segment1,itm.description;
select distinct SUBSTR( kmt.tag_number, 1,6), fa.model_number from kfupm_mcr_tag kmt, fa_additions fa
where kmt.TAG_NUMBER =fa.TAG_NUMBER ;
and fa.model_number is not null;
union all is not working.
Regards
Arifuddin

While using the set operators, to match the number of columns in the SELECT list you can make use of NULL as:
SELECT COL_NAME1,COL_NAME2,COL_NAME3
FROM TAB_NAME1
UNION
SELECT COL_NAME1,COL_NAME2,NULL
FROM TAB_NAME2The columns in the both SELECT lists should be same and also the datatype. The resultant of the query will be the columns of first SELECT list (column aliases)

Similar Messages

  • How to join these two queries

    Hi experts,
    I need to join two queries but not sure how:
    select id from test_table1;
    select *
      from table(f_function(null
                           ,null
                           ,1 -- the id
                           ,sysdate);One query has IDs needed to run the second query. Is there a way to join those two?
    The result should be all columns from test_table1 + all columns from f_function.
    Best regards,
    Igor
    Edited by: Igor S. on Mar 8, 2013 5:18 AM

    Hi,
    Igor S. wrote:
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    ) xyz
    where test_table1.id = xyz.id
    /So these two queries are the same?Try it and see.
    You'll find that the 2nd one produces an error. But if you change it to
    select  *
      from  test_table1,
            table(
                  f_function(
                             null,
                             null,
                             id,
                             sysdate
                            )      -- No alias here
                 ) xyz             -- Alias here, instead
    where test_table1.id = xyz.id
    /Then, assuming f_function produces a column called id, it will work.
    Whether it produces the same results or not depends on what the function returns, and whether either id is NULL.
    If the id column that the function returns is the same as the id value that you pass to it, and is never NULL, then the 2 queries will produce the same results.
    Either way, each row of test_table1 will be joined to each row that the function produces with the argument(s) from that row. The column names produced by the function and the values in those columns are determined by the function; they do not need to have anything in common with any table. In practice, a function like f_function will usually not return an column that is always identical to any of its inputs, since that value is already available from the input.

  • How do I connect two Queries?

    Hello all,
    How do I connect two Queries and add some numbers.
    Here is what I am trying to do.
    Query 1: Gets G/L Credit Amounts for Jan 2007  Feb 2007 March 2007.....Dec 2007
    Query 2: Gets G/L Debit Amounts for Jan 2007 Feb 2007 march 2007.....Dec 2007
    I need to put both these Queries in a worksheet one below the other and add the totals by each month.....so the final report looks something like this:
    I am using two structures to hold the query values.
    G/L Credit Amount        Jan 2007    Feb 2007.............Dec 2007
                                        +100         +200                   +400
    G/L Debit Amount           -50           -100                     -200
    Total                              50             100                      200
    Also, I would like to allow the users to enter Year as a variable. Any suggestions?
    Your help is greatly appreciated.

    Venkata,
    Thanks for your reply. Could you explain how I insert two query results into one worksheet? And, also how do I link the two structures ( one structure per query) so I can total the amounts by each month?
    Thank you in advance.

  • How to JOIN the results of multiple SELECT statements

    Hello,
    I currently have a table where each row represents a single census date for a given tag number, where each tag number can have multiple census dates and data which are represented by their own row in the table.
    I currently have 2 SELECT statements that select all tag numbers given a census date, and would like to combine those 2 queries so that the data is presented in a manner such that for each tag number, instead of obtaining 2 rows for each tag number, I would be presented with 1 row for each tag number consisting of three columns: tag_number, data1, and data2.
    Both of the requested dates are not necessarily present for all tag numbers, and in the event that only one date is present, the other column should contain null, but if both dates are not present for a given tag number, the tag number is omitted.
    The two queries I would like to JOIN are:
    SELECT a.tag_number, a.data AS data1
    FROM tab1 a
    WHERE
    a.census_date='11/21/2009'and
    SELECT b.tag_number, b.data AS data2
    FROM tab2 b
    WHERE
    b.census_date='11/24/2009'The table from which I am selecting the data looks like such:
    tag_number  census_date     data
        1       11/21/2009      10
        1       11/23/2009      11
        1       11/24/2009      12
        2       11/19/2009      13
        2       11/21/2009      14And the data that I would like to result looks like:
    tag_number  data1           data2
        1       10              12
        2       14              nullAny help would be greatly appreciated.
    Thank you in advance,
    -Justin
    Edited by: m8r-qbkka9 on Nov 24, 2009 4:17 PM

    Hi,
    This looks like a job for pivot
    SELECT       a.tag_number
    ,       MAX (CASE  WHEN a.census_date = TO_DATE ('11/21/2009'
                                                       'MM/DD/YYYY'
                   THEN a.data
                END
               )          AS data1
    ,       MAX (CASE  WHEN a.census_date = TO_DATE ('11/24/2009'
                                                       'MM/DD/YYYY'
                   THEN a.data
                END
               )          AS data2
    FROM      tab1    a
    WHERE       a.census_date  IN ( TO_DATE ( '11/21/2009'
                                      , 'MM/DD/YYYY'
                       , TO_DATE ( '11/21/2009'
                                      , 'MM/DD/YYYY'
    GROUP BY  a.tag_number
    ;Comparing DATEs to stirngs, like '11/24/2009', is simply asking for trouble.
    Always use a conversion function (like TO_DATE) or DATE literals instead.

  • Workbook using the two queries

    hi
    can we insert two queries in a single workbook, how to accomplish this !
    if some workbook is using the two queries how can we verify this.

    Hi Sun,
    To have more than one query in the same workbook,you can just do this.
    Goto Business Explorer --> Analyser > Open the first query and  click on Business Explorer>Tools and select the option " Insert Query" .
    Hope this works.Assign points if it is helpful
    Regards,
    Balaji
    Message was edited by: balaji vijayakumar

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • Hi - I'm trying to sync iBooks on my Macbook Pro with iBooks running on my iPad. I have some pdf's download from the net I want to share between devices and I can't work out how to sync the two devices. Any help please?

    Hi - I'm trying to sync iBooks on my Macbook Pro with iBooks running on my iPad. I have some pdf's download from the net I want to share between devices and I can't work out how to sync the two devices. Any help please? I'm running Mavericks

    Thanks for your help Brij011 - much appreciated. Apologies as I'm a newbie but I've looked at the info for synching and I appear to have all the switches flicked on my iPad. Does the iPad and iBooks only sync in iCloud for purchases as I appear to be doing something wrong. I could sync ok when books was in iTunes but since migrating to Mavericks I think I'm doing something wrong!!

  • How to send the two PDF attachments into one mail

    Hi Team,
    I need one requirement...I have two forms ,one is cover sheet and another one is form data. These two forms are converted into two PDF documents and sent to vendor as mail attachments...
    Please suggest me,  how to send the two attachments through one mail .....
    Thanks & Regards,
    Samantula.

    Please SEARCH in SCN before posting. There are lots of threads related to send mail with multiple attachments.

  • How to pass the two viewname in narative View

    Hi all,
    How to pass the two viewnames in the narative view.
    Ex.<iframe src="saw.dll?Go&Path=/shared/Subjectarea/Domain/Reports/Detailed%20reports/Sub%20Reports/Monthly/Report17&Action=Navigate&ViewName=tableView!1+&ViewName=tableView!+2&P0=1&P1=eq&P2=%22Dim%20Time%22Time%20Key%22&P3=@19&Options=d" Width=500 Height=500 frameborder=0 Align=MIDDLE></iframe>
    thanks,
    Siva

    Hi Siva,
    I could be mistaken, but I do not think you can reference two views via URL.
    The proper way to achieve what you asking is to use the Compound View object. The compound view acts like a wrapper to multiple views. And the best part about it is that you can have as many compound views you want in the same Answer request. By default, all requests start out as a compound view that has a title view and a table view. However, if you click the "Duplicate, specialize or delete current view" button, you can add a "New" compound view. That way a single Request can have many different layouts. Then when you want to reference a particular layout, you reference that particular compound view.
    So in your situation, assuming you create a new compound view to store your layout, you can reformat your code as follows:
    <iframe src="saw.dll?Go&Path=/shared/Subjectarea/Domain/Reports/Detailed%20reports/Sub%20Reports/Monthly/Report17&Action=Navigate&ViewName=compoundView!2&P0=1&P1=eq&P2=%22Dim%20Time%22Time%20Key%22&P3=@19&Options=d" Width=500 Height=500 frameborder=0 Align=MIDDLE></iframe>
    Good luck and if you found this post useful, please award points!
    Best regards,
    -joe

  • How to play the two video files simultaneously in Xletview

    Hi All,
    How to play the two video files simultaneously in Xletview. But only one video must be visible to user and the other video must run in the background(Invisible to user). I need to implement like broadcasting channel, I don't want to stop the current video while switching to another video and vice versa.
    Is it possible to do in Xletview 0.3.6?. Or Anybody tried this?...
    Sourab.

    I think no one try this with xletview!
    xletview is not for that!

  • Need to join the two xml type output in plsql function

    Hi,
    I need to join the two xml type output in plsql function. Could you help me out?
    Sample function:
    function func_ret_stk return xmtype
    xmloutput_stk xmtype;
    xmloutput_desp xmtype;
    begin
    xmloutput_stk := --------;
    xmloutput_desp :=---------;
    return xmloutput_stk + xmloutput_desp;
    end ;
    Thanks in Advance,

    Hello,
    this is the forum for the tool {forum:id=260}.
    Please ask your question in {forum:id=157} or {forum:id=34}
    Regards
    Marcus

  • How to find the standard queries in business content

    hi
    pls explain how to find the standard queries in a business content
    assign full points

    Hi,
    Incase you want to know details about the standard queries, then the best source would be the help documenations on BI content:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/37/5fb13cd0500255e10000000a114084/frameset.htm

  • How to assign the two values for constant (same key)

    How to assign the two values for constant (same key)
    CONSTANTS: c_pstkey TYPE  bschl VALUE '09',
               c_splgl  TYPE  umskz VALUE 'I',
               c_buzei  TYPE  buzei VALUE '001'.
    using BSCH1 again i have two asign vaue
    can you just let me know
    Edited by: sravya_se38 on Nov 23, 2010 12:14 AM

    You can create a structure for that constant .
    You can define in this way
    CONSTANTS : BEGIN OF c_pstkey,
                             01 TYPE bschl VALUE '01',
                             02 TYPE bschl VALUE '02',
                          END OF c_pstkey.
    and can access using...
    c_pstkey-01, c_pstkey-02 ........

  • I bought two films on my ipod tough 4g ( normally comes up on my ipad if i have bought something on my ipod) but i dont know how to get the two films on my ipad without paying for them.

    I bought two films on my ipod tough 4g ( normally comes up on my ipad if i have bought something on my ipod) but i dont know how to get the two films on my ipad without paying for them.

    Movies work differant than TV shows, music and apps. With movies, to get them from one device such as an iPod Touch to an iPad, you would need to connect the Touch to your computer first and in iTunes under the file menu, hit transfer purchases. Next connect the iPad and you can sync the movie to the iPad.
    While the iPad is connected to the computer, in iTunes, click on the iPad in the left pane and when the screen loads, click movies and from there, you can select the movie that you want to sync.

  • How to join this two query

    Hi all,
    i have these two query .
    SELECT A.DATENUM,A.ATT_STATE,B.OT_MINUTES FROM WEB_HR.HR_ATTENDANCE A,WEB_HR.HR_OVERTIME B
              WHERE A.MONTH_ID=2 AND A.ATT_YEAR=2009 AND A.EMP_ID=1 AND A.EMP_ID=B.EMP_ID
              AND A.COMPANYCODE=1 AND A.DATENUM<=16 ORDER BY a.DATENUM;
              SELECT A.DATENUM AS VDATENUM,A.ATT_STATE AS VATT_STATE,B.OT_MINUTES AS VOT_MINUTES FROM WEB_HR.HR_ATTENDANCE A,WEB_HR.HR_OVERTIME B
              WHERE A.MONTH_ID=2 AND A.ATT_YEAR=2009 AND A.EMP_ID=1 AND A.EMP_ID=B.EMP_ID
              AND A.COMPANYCODE=1 AND A.DATENUM >16 ORDER BY a.DATENUM;
    actually from these two query each query returning 3 column each .
    so what i need is i want mearge these two in such way that it return 6 column at a time..
    can i get this??

    You can do that by just joining them. Let's assume your two queries are Q1 and Q2, both with columns c1-3, then just:
    select q1.c1, q1.c2, q1.c3, q2.c1, q2.c2, q2.c3
    from (Q1) q1
        ,(Q2) q2But this will result in a cartesian product of the two resultsets (from Q1 and Q2).
    The big question is how do you want to combine the rows that come out of Q1 with the rows that come out of Q2. For instance if DATENUM is unique in both resultsets, and you want to combine rows that have matching values on DATENUM (c1, below), then:
    select q1.c1, q1.c2, q1.c3, q2.c1, q2.c2, q2.c3
    from (Q1) q1
        ,(Q2) q2
    where q1.c1 = q2.c1Toon

Maybe you are looking for

  • I am trying to scan a document, but my printer utility will not give me the option to scan.

    I am trying to can a document on my computer.  However, when I bring up the printer utility it does not give me the option to scan.  I have a laptop that does allow this option, but I don't want to go through the hassle of downloading to one device a

  • Exception message not thrown back to the page

    Hello All, I have a servlet that listens for some data. Everything works perfectly if the data is intact. I do a whole bunch of processing on the data and verify its integrity etc... HOwever if something is wrong, my app throws an exception and I cou

  • NO WIP Quantity Found

    Dear All While adding Receipt from Production system throws an following error "No WIP Quantity Found" How to resolve this. Kindly do the needful Thanks & Regards Venkatesh N

  • Exporting "Original" from iPhoto '09 v8.1.2(424) to External Hard Drive

    RMS3RD  Re: error writing to disk     Feb 6, 2014 8:40 AM    (in response to Terence Devlin)  Terence, not sure of the etiquette here but this is similar to what I am experiencing: CPE: MacBook Pro 5,5 Core2Duo running OSX 10.5.8 with EHD  Seagate Ba

  • Submit batch job and return control to the user

    Hi Have a situation where we need to submit a batch report and then return control to the user of the application before the report is finished. What is the best way to do this? The old application is written using Java and the application is using t