Combining two queries to one

I have two queries and I would like to output the results as
one and sort by Name ASC
Any help would be great thanks

Either use union in your SQL query or use Coldfusion to
combine exisitng queries and create a new query resultset.
Something like this:
<CFQUERY NAME="getDetailsQuery1"
DATASOURCE="#DSNNAME#">
SELECT * FROM getDetailsA
</CFQUERY>
<CFQUERY NAME="getDetailsQuery2"
DATASOURCE="#DSNNAME#">
SELECT * FROM getDetailsB
</CFQUERY>
<CFQUERY NAME="getDetails" DBTYPE="query">
SELECT * FROM getDetailsQuery1
UNION
SELECT * FROM getDetailsQuery2
ORDER BY Name ASC
</CFQUERY>
Hope this helps!
Cheers / Manu.

Similar Messages

  • Combining two queries in one..

    Hi,
    Can someone tell me how to combine follwoing two queries in one so that it will increase performance..
    SELECT single PLNNR from AFKO
           into T1
           WHERE AUFNR = '007200000100'.
    SELECT single STATU from PLKO
           into T2
           WHERE PLNNR = T1.

    using subqueries it is possible
    select single statu from plko into t2 where plnnr in (select single plnnr from afko where aufnr eq '007200000100').
    read about subqueries at this link...
    http://help.sap.com/saphelp_erp2004/helpdata/en/dc/dc7614099b11d295320000e8353423/frameset.htm
    regards,
    PJ

  • How to Combine two queries into One

    Hi Gurus,
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL>
    I have following two queries. How I can convert these two queries into one with the same result ?
    Q1
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=32
    AND venddate is null
    AND vid in(select vid from view_vid where type='PDX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=55)
    AND (id,vdate) in (select id,vidate from market_data where marketed_date is null)
    AND id not in (select id from location)
    Q2
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=20
    AND venddate is null
    AND vid in(select vid from view_vid where type='PBX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=40)
    AND (id,vdate) in (select id,vidate from market_data where region_date is null)
    AND id not in (select id from location)
    I can UNION these two queries, but, is there any way I can write a single query with which gives me same result as above two queries?
    Any help would be highly appreciated
    Thanks in advance

    Hi,
    You can do something like this, which will be more efficient than a UNION:
    SELECT  id, vdate, vendorname, venddate, vid
    FROM  vendor
    WHERE  (   (    -- Conditions that apply only to q1
                               processid = 32
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PDX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 55
                AND (id,vdate) IN ( SELECT id, vidate
                                    FROM   market_data
                                    WHERE  marketed_date IS NULL
            OR  (  -- Conditions that apply only to q2
                     processid = 20
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PBX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 40
                AND (id,vdate) IN ( SELECT  id, vidate
                                    FROM  market_data
                                    WHERE  region_date IS NULL
                   -- The remaining conditions apply to both q1 and q2
    AND     venddate   IS NULL
    AND     id         NOT IN (SELECT id FROM location)
    I hope this answers your question.
    If not, post  a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to combine two queries in one EXCEL

    hi i got one requirement
    i got one excel sheet  from user which contains two  report s(hoe we know whether it is worknook or not) of  2011 data and now user wants 2012 data .now i icluded jan 2012 to dec 2012 in two reports and sent to user.But user is asking these two reports want to see in one sheet.
    so how can i proceed: if i go for work  book  how can i include these two reports in workbook and here my doubt is if i create a workbook based on  these two querie which name i have to give user.Please help me out on the same.
    Regards,
    Madhu.

    Hi Madhu
    Run one query. Click on a empty space in the excel
    From the BEx Design Toolbar -
    >Insert Analysis Grid -
    > Right click on the Design Item
    Edit the DataProvider.....You can ran same or different query with selection. 
    Save the result
    Check this link for detail....I am also searching for something with screenshot
    Regards
    Anindya
    Edited by: Anindya Bose on Feb 14, 2012 3:04 AM

  • Combining two queries into one query if possible

    Hi there. I would like, if possible, to somehow combine the queries 1) and 2) into a single query.
    1) select distinct user_id from system_user_sessions;
    This query returns all unique users from the indicated table.
    2) select count(session_id) from system_user_sessions where user_id = "each user_id returned from 1)";
    This query will return, for each distinct user_id, the number of sessions involving that user. In other words I would like to return the user_id of each user together with the number of session_ids involving that user.
    any ideas? Joe

    I assume you are looking for something like this:
    select count(session_id)
      from system_user_sessions
    where user_id in ( select distinct user_id
                          from system_user_sessions
                      );HTH
    Ghulam

  • SAP XI - Combine Two files as one in File Adapter

    Experts,
    I want to combine two files as one in File adapter itself.  I am using a simple scenario of File-to-File where i am just sending the file from sender to receiver as it is , EXCEPT, i want to add one line at the end of the file .
    I was thinking of doing this in File adapter , avoiding any mapping program in Integration Repository ..
    ANY INDEA's ??
    Regards,
    Ashutosh

    Hey
    You have 3 options,first one can be to execute a OS command before message processing or use adapter modules to append the new line in the sender adapter.
    the second option(and better one) is to do this via message mapping.
    third option is to write a OS script and execute it after message processing on receiver file adapter.
    one thing you need to make sure is that since OS scripts run on XI server itself(not on FTP server) so in case you are picking file from FTP server and delivering to FTP ,then you can't use option 1 or 3,you can only use option 2
    Thanx
    Aamir

  • How do I combine two regents into one in Logic Pro Arrange?

    how do I combine two regents into one in Logic Pro Arrange?

    Thanks for your input kcstudio. I would still be left with 2 regions although one after the other, on one track.
    I am trying to save steps of the way I am combining the info of 2 seperate regions into one: bouncing the 2 tracks then re-importing that audio back into the project. It would save a lot of time if you could just drag one region on top of the other
                                W.W.

  • Combining two messages into one

    Hello,
    I have a mapping issue, I have a business process in which I have to combine two messages into one.
    To do so, I have defined a message mapping in which there are two source message types, and one target message type.
    When testing the message mapping in the IR, it works fine, but when I define and test an interface mapping with that same message mapping, I receive this error message:
    "Cannot produce target element /ns0:Messages/ns0Message1/MY_IDOC_TYPE/MY_SEGMENT. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd."
    What am I doing wrong ?
    How am I supposed to combine two messages into one ?
    Thanks,
    Elad.

    Hi Elad,
    Just see if you have included both you source message interfaces and one target nessage interface correctly in while doing your interface mapping.....
    The most common mistake made when we do scenarios which include combination of two source message types into one target type are:
    - we forget to include both the source message interfaces.
    - or we interchange between one of the source message interface with the target.
    Just see if either of the 2 is aplicable in your case and just activate all components as and when you create them..
    Regards,
    abhy

  • Two Queries in one XSQL-Template

    Hi there,
    is it possibile to use two queries in one xsql-template, which are generated two seperated trees of XML?
    I think about something like that
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsql:query connection="bynet"
    null-attribute-indicator="true"
    xmlns:xsql="urn:oracle-xsql"
    rowset-element = "COLLECTION"
    tag-case="upper"
    row-element = "FIELD"
    id-attribute = "">
    select c_formtype from offer_collection
    </xsql:query>
    <xsql:query connection="bynet"
    null-attribute-indicator="true"
    xmlns:xsql="urn:oracle-xsql"
    rowset-element = "COLLECTION2"
    tag-case="upper"
    row-element = "FIELD"
    id-attribute = "">
    select c_formtype from offer_collection2
    </xsql:query>
    which should give me
    <COLLECTION>
    <FIELD>
    <C_FORMTYPE>lala</C_FORMTYPE>
    </FIELD>
    </COLLECTION>
    <COLLECTION2>
    <FIELD>
    <C_FORMTYPE>lala</C_FORMTYPE>
    </FIELD>
    </COLLECTION2>
    Any way to do this?
    Thanx for help,
    Christian Hartmann

    Sure, just enclose two <xsql:query> tags by any other outer tag:
    <something xmlns:xsql="urn:oracle-xsql" connection="demo">
    <xsql:query> select * from emp </xsql:query>
    <xsql:query> select * from dept</xsql:query>
    </something>

  • HT4759 How do I combine two accounts into one

    How can I combine two accounts into one account

    If you are talking about iCloud accounts, you can't.
    Or you could tell us what type of accounts these are?

  • Combining two queries in a join

    SQL> desc messages;
    Name Null? Type
    MESSAGEID NOT NULL NUMBER
    TITLE NOT NULL VARCHAR2(50)
    AUTHOR VARCHAR2(20)
    BODY NOT NULL VARCHAR2(4000)
    BOARD NUMBER
    THREAD NOT NULL NUMBER
    DATE_CREATED NOT NULL DATE
    SQL>
    I'm trying to combine both queries outlined below. The first query
    selects the very first message created in the messages table. It does
    this by checking whether thread=0. If it is that means it started a message.
    The second query checks the number of replies to the thread above.
    The replies to the above message
    will have a thread value the same as the above messageid.
    That is how a reply is identified.
    I am trying to do both queries in one so that the output has
    the starting message first with the name
    of the person who created the new thread(author), date_created, etc....below that
    then is the
    number of replies to the message,the author of each reply and the date....
    I'm using oracle 8i so i cant use the join key word...
    any ideas would be appreciated.
    ----selects message that started thread---------------------------------
    select b.title,b.boardid,m.messageid,m.title,m.author,
    m.date_created,m.body
    from messages m, boards b where b.boardid=m.board and m.thread=0 and b.boardid='198'
    and m.messageid='241';
    Thread title Author Starting message Last post
    Austrailia noel Austrailia 04/01/2005 21:22:35
    -----selects replies to the above message-----------
    select author,date_created,body
    from messages
    where board=198 and thread=241;
    AUTHOR DATE_CREATED BODY
    noel           05-JAN-05 Oz is played on clay
    noel 05-JAN-05 Oz played on grass
    noel 05-JAN-05     Oz played on grass

    This is a duplicate post of the following thread:
    URGENT: combining two sql statements

  • Confused on syntax-combine two queries

    I have two queries that I'm trying to combine, but can't figure out how to combine them ... successfully!?! The first query is pretty simple in that I'm looking at several fields from two different tables, no big deal.
    The second query calculates the years, months, days between two dates that are used in the first query. I'm stumped on how to combine the queries so that they place nice with each other and return results.
    Here's the first query ...
    select
    RTRIM(RTRIM(vpi.LastName) + ', ' + RTRIM(ISNULL(vpi.FirstName,''))) Employee,
    convert(varchar,vpi.FromEffectiveDate,101) PositionStart,      
    convert(varchar,vpi.ToEffectiveDate,101) PositionChange,
    convert(varchar,vpi.PositionStartDate,101) PositionStartDate,
    vpi.PositionReason, vpi.PositionCode, vpc.PositionCodeDescription
    from vhrl_positioninfo vpi
    inner join position_codes vpc on vpi.PositionCode = vpc.PositionCode
    Here's the second query ...
    select
    [Age] = convert(varchar, [Years]) + ' Years ' +
              convert(varchar, [Months]) + ' Months ' +
              convert(varchar, [Days]) + ' Days',     *
    from
         select
              [Years] = case     when BirthDayThisYear <= Today
                        then datediff(year, BirthYearStart, CurrYearStart)
                        else datediff(year, BirthYearStart, CurrYearStart) - 1
                        end,
              [Months]= case     when BirthDayThisYear <= Today
                        then datediff(month, BirthDayThisYear, Today)
                        else datediff(month, BirthDayThisYear, Today) + 12
                        end,
              [Days]= case     when BirthDayThisMonth <= Today
                        then datediff(day, BirthDayThisMonth, Today)
                        else datediff(day, dateadd(month, -1, BirthDayThisMonth), Today)
                        end,
              Birth = convert(varchar(10) ,Birth, 121),
              Today = convert(varchar(10), Today, 121)
         from
              select     BirthDayThisYear =
                   case     when     day(dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth)) <> day(Birth)
                        then     dateadd(day, 1, dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth))
                        else     dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth)
                        end,
                   BirthDayThisMonth =
                   case      when      day(dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth)) <> day(Birth)
                        then     dateadd(day, 1, dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth))
                        else     dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth)
                        end,
              from
                   select     BirthYearStart = dateadd(year, datediff(year, 0, Birth), 0),
                        CurrYearStart = dateadd(year, datediff(year, 0, Today), 0),
                        BirthMonthStart = dateadd(month, datediff(month, 0, Birth), 0),
                        CurrMonthStart = dateadd(month, datediff(month, 0, Today), 0),
                   from          
                        select birth = convert(datetime, fromeffectivedate) ,
                        Today = case when convert(datetime, toeffectivedate) = '3000-01-01'
                                       THEN convert(datetime, convert(int,getdate()))
    else vpi.toeffectivedate
    end
         from vHRL_PositionInfo vpi inner join position_codes vpc
                        on vpi.PositionCode = vpc.PositionCode
                   ) aaaa
              ) aaa
         ) aa
    )a
    Here's the sample data ...
    vpi table ...
    LastName FirstName FromEffectDate ToEffectDate PosStartDate PosReason PosCode
    Doe John 2001-10-15 3000-01-01 10-15-2001 Transfer OperPack
    Smith Tom 1994-11-28 2001-10-14 1994-11-28 New Hire OperDC
    vpc table ...
    PosCode PosDescription
    OperPack Pack Line Operator
    OperDC Descaler Operator
    This is what the results should look like ...
    John, Doe 2001-10-15 3000-01-01 10-15-2001 Transfer OperPack Pack Line Operator 6 Years 11 Months 16 Days
    John, Doe 1994-11-28 2001-10-14 1994-11-28 New Hire OperDC Descaler Operator 6 Years 6 Months 19 Days
    I know the date calculation piece adds 5 additional fields to the end, but they are not needed for the final report. Any help would be greatly appreciated! Thank you! Jena

    Your query suggests you're not using Oracle. Please post in your relevant database forum.

  • How to combine two albums in one ?

    Hi, I bough a new mac and with it came the fastideous task of re-adding all the albums to iTunes once again.
    Everything was going fine until I added a album which has 2 CDs 14 tracks in one CD and 5 more in a Bonus CD what happen when I added the CDs to the library was that iTunes made two different albums.
    I tried changing the info, the name of album, the name of the artist even the release year everything was equal, yet iTunes didn't combine the two albums in one as it should.
    After I selected both albums went to get info, options and in the Part of a compilation I selected Yes, which made the smaller album to disapear, the songs are in the library, but the album disappeared from the album library.
    Any suggestion ?

    Generally setting a common Album title and Album Artist will fix things.
    For deeper problems see Grouping tracks into albums.
    Closing and reopening iTunes will usually restore any album that "disappears" after an edit.
    tt2

  • How to combine two photos in one without white border?

    I am trying to combine two different photos next to each other (each 10 cm * 7.5 cm) in one of 10 cm * 15 cm and save it as a jpg file. Unfortunately when I do this in the print module (custom package) I get a file with a white border. I have set up page settings to 10*15 cm without border. How can I get a combined file without a border?

    Titas,
    This involves row level comparison of the report column data values we can achieve this in BI Publisher but at answers level there is no option.
    Thanks,
    Saichand

  • How do I combine two arrays into one?

    I am trying to combine two byte arrays into one. What function do I use that will put in the information in the same order just combined?

    battler. wrote:
    Julien,
    Used LV for years.  Never knew that (concatenate inputs).  Wouldn't believe the lengths ive used to get around it.  Thanks
    Same here! I actually learned about it taking a sample test for the CLAD.
    Richard

Maybe you are looking for

  • Procurement of non valuated materials Problems at PR Conversion time

    Dear Gurus, I need a hand on defining settings for non valuated stock materials procurement. 1-> Am using a copy of non valuated material type UNWB to which i added Accounting views )for GL acc determination through valuation class). 2-> In OPPQ, "Ac

  • Repairing lv 2012 installation

    To increase my hard disk space, I have deleted some of the older version of LabVIEW, including LV861, 2009, 2010, and 2011.  Now my new installation of 2012 will not run.  I have tried to repair the installation, but it has asked for the LV861 instal

  • Is SAP on Linux mature enough for productive use ?

    Hi I’m not quite sure if this is the correct forum for this question – But I’ll risk it anyway We are starting a SAP project from scratch – and my manager has asked if we could run the solution on Linux. I know that Linux is supported by SAP, but is

  • Cant install mysql

    Hello. When I try to install MySQL I get this: chown: invalid user: `mysql' chown: invalid user: `mysql' chown: invalid user: `mysql' Installing MySQL system tables... 101026 20:31:59 [ERROR] Fatal error: Can't change to run as user 'mysql' ;  Please

  • Hi, Mac will not start

    Hi, Last night i downloaded flip for mac & a Samsung software (propably Windows) for my mobile phone... before shutting down i was asked if i want to install & restart, i said yes, after installation, now my mac will not start.... how can i go about