These two queries return same data?

select * from voucher where (unit = 'TIA4M' or unit = 'TIAFM' or unit = 'TIAWM' or unit = 'TIATW' or unit = 'TIAPA' )
and invoice_dt >= TO_DATE('01/01/2006', 'MM/DD/YYYY')
select * from voucher where unit in ('TIA4M', 'TIAFM', 'TIAWM', 'TIATW', 'TIAPA')
and invoice_dt >= TO_DATE('01/01/2007', 'MM/DD/YYYY')
Also the first is much faster right?

The first query is using a date of Jan 1, 2006. The second query is using a date of Jan 1, 2007.
Assuming that is a typo, the two queries are semantically identical. Since Oracle can easily transform an IN-list to a series of OR's, though, I would doubt that there would be any performance difference between them absent the 2006/2007 change.
Justin

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.

  • Whats the difference between these two queries ? - for tuning purpose

    Whats the difference between these two queries ?
    I have huge amount of data for each table. its takeing such a long time (>5-6hrs).
    here whice one is fast / do we have any other option there apart from listed here....
    QUERY 1: 
      SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end)
        FROM
          tab1 inner join tab2 on condition1 inner join tab3 on condition2 inner join tab4 on conditon3
        WHERE
         condition4..10 and
        GROUP BY
          field1, field2,field3
        HAVING
          sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end) <> 0;
    QUERY 2:
       SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0))
        FROM
          tab1, tab2, tab3, tab4
        WHERE
         condition1 and
         condition2 and
         condition3 and
         condition4..10
        GROUP BY
          field1, field2,field3
        HAVING
          sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0)) <> 0;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    My feeling here is that simply changing join syntax and case vs decode issues is not going to give any significant improvement in performance, and as Tubby points out, there is not a lot to go on. I think you are going to have to investigate things along the line of parallel query and index vs full table scans as well any number of performance tuning methods before you will see any significant gains. I would start with the Performance Manual as a start and then follow that up with the hard yards of query plans and stats.
    Alternatively, you could just set the gofast parameter to TRUE and everything will be all right.
    Andre

  • Report with two Command is empty if one of the two commands returns no data

    Hi all,
    I have a report with two Commands not linked together.
    If ONLY one of the two Commands returns no data, the full report is empty (although the other Command returns data).
    I'm using Crystal Report 2008 and the CRJ 12.2.205
    Have an idea?

    Hi Ted,
    how can I solve the problem, please? It is important.
    If I can help yourself, the problem is appeared in many reports since I updated the library (the old library version 11.8.4.1094 works fine with all). I'm waiting for your answer, please.
    Thank you very much.

  • Joining these these two queries (one regular and one grouped)

    Hello
    I have these two queries I would like to join, however the later is a grouped query how can I join it with the first query?
    Has to be joined on EventId. The second query is a total table scan.
    SELECT AH.EventID,
    AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
    AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
    AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
    FROM AlarmHistory AH
    WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
    ((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
    (NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
    ORDER BY AH.EventID DESC
    SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
    FROM alarmHistoryLog ia
    INNER JOIN alarmHistoryLog r
    ON ia.EventId = r.EventId
    AND r.EventTypeId = 2
    AND r.EventSeq = (SELECT MIN(eventSeq) FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
    WHERE ia.EventTypeId = 0
    group by ia.EventId
    order by EventId desc
    Henry

    Try the below:
    ;with ctefirst as
    SELECT AH.EventID,
    AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
    AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
    AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
    FROM AlarmHistory AH
    WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
    ((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
    (NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
    ), ctesecond as
    SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
    FROM alarmHistoryLog ia
    INNER JOIN alarmHistoryLog r
    ON ia.EventId = r.EventId
    AND r.EventTypeId = 2
    AND r.EventSeq = (SELECT MIN(eventSeq)
    FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
    WHERE ia.EventTypeId = 0
    group by ia.EventId
    Select A.*,B.seconds,B.AlarmSessions From ctefirst A
    Inner join ctesecond B On A.EventId = B.EventID
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
     [Blog]

  • Joining these two queries

    I have two queries. The First one is long but very simple. All it has is long list of columns.
    First one:
    SELECT CL.CLIENT_ID, CA.CASE_ID, to_char(SYSDATE,'RRMMDD'),
    CL.MASTER_CLIENT_ID,
    CL.NAME1,
    nvl(CL.NAME2,' '),
    nvl(CL.ADDRESS1,' '),
    nvl(CL.ADDRESS2,' '),
    CL.POCO_POSTAL_CODE, nvl(CL.CITY,' '),
    nvl(CL.AUTO_SURV_CODE,0),
    CA.Col_Collector_Id
    FROM CLIENT CL, CASES CA
    WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID AND
    CA.CASE_ID = :current_case_id
    Second one:
    SQL SELECT nvl(REF_NO,' '), nvl(to_char(DATE_OF_JUDGEMENT,'rrmmdd'),' ')
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8) AND
    CA_CASE_ID = :current_case_id AND
    PETITION_DATE = (SELECT max(PETITION_DATE)
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8)
    AND CA_CASE_ID = :current_case_id
    AND ROWNUM < 2 );
    The :current_case_id is passed as a parameter. The table in the second query i.e. CASE_INSTANCES is related to the first query with the CA_CASE_ID. Not all records fetched by the first query have a record in the second query. So you might have to use a LEFT JOIN or something. trying to join these two has worn me out. Please help me out someone.

    Hi,
    Simplified Solution:
    SELECT * FROM (
                        SELECT CL.CLIENT_ID, CA.CASE_ID, TO_CHAR(SYSDATE,'RRMMDD'),
                        CL.MASTER_CLIENT_ID,
                        CL.NAME1,
                        NVL(CL.NAME2,' '),
                        NVL(CL.ADDRESS1,' '),
                        NVL(CL.ADDRESS2,' '),
                        CL.POCO_POSTAL_CODE, NVL(CL.CITY,' '),
                        NVL(CL.AUTO_SURV_CODE,0),
                        CA.Col_Collector_Id
                        FROM CLIENT CL, CASES CA
                        WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID ) a,
                        (SELECT NVL(REF_NO,' '), NVL(TO_CHAR(DATE_OF_JUDGEMENT,'rrmmdd'),' '),CA_CASE_ID
                             FROM CASE_INSTANCES
                             WHERE IN_INSTANCE_TYPE IN (1,8) AND
                             CA_CASE_ID = :current_case_id AND
                             PETITION_DATE = (SELECT MAX(PETITION_DATE)
                                                      FROM CASE_INSTANCES
                                                      WHERE IN_INSTANCE_TYPE IN (1,8)
                                                      AND CA_CASE_ID = :current_case_id
                                                      AND ROWNUM < 2
                        ) b
    WHERE a.case_id = b.ca_case_id(+)
    Regards
    K.Rajkumar

  • Show Rows Where Two Columns have Same Data

    Hello,
    I have a spreadsheet that I need to sort by showing me all the rows where the data is equal between two columns.
    I.E. I have a column called Last Name and I have another column, U, with some of those Last Names, I want to sort the spreadsheet to show me only the rows that match up with the same Last Name in coumn a and U.
    Thanks for any help.
    L

    To sort the table:
    Add two columns to the table. For this discussion, I'll refer to them as columns AA and AB.
    In AA2, enter: =ROW()
    Fill to the bottom of the table. With all f these cells selected, Copy, then Edit > Paste Values.
    This gives you a column you can sort by to restore the original order of the table.
    In AB2, enter: =IF(A=U,U," ") using option-space between the double quotes.
    Visually, this will repeat the duplicated names once more in column AB.
    An ascending sort on column AB will bring all rows with duplicate data in columns A and U to the top of the table.
    For greater visibility You might also add a conditional format rule to all of column AB, as I've done here for column D:
    The box to the right of "Text doesn't contain" contains a single 'option-space' character. The ascending sort (on column D) has not yet been done.
    Regards,
    Barry

  • How to access a Network Share between two servers in same data centre

    I have two dedicated servers (both Windows 2012 Server) hosted in a data centre somewhere.   I want to share a folder on one server with the other server, but it's obviously not as straight forward as one might think.  My servers are called "Maximus"
    and "Apprentice".
    On Maximus I shared a folder by right clicking on it and choosing "Share with... / Specific People", I then typed in the name of a local user account which also exists on Apprentice with the same name and password.  (so each server has a local
    user account with the same name and password).
    So then on Apprentice, I was hoping I could access the share (while being logged in as this user with whom the folder was shared) by simply typing  "\\ipaddress\sharename" into the address bar in file explorer.  Unfortunately it comes
    back with "Windows can not access [ip address]".
    Now, I do have a website setup on the IP address for Maximus.  This is actually the reason I want to create this share.  I need the second server for load balancing and need to share IIS config as well as the website itself.  (So I will need
    two shares eventually, but for now I'm just trying to get one to work).  I don't know if the fact that the ip address is pointing to the website is causing me problems here or if it's something else.
    Are there any network gurus out there who can tell me what the issue is and how to resolve it?

    I can ping both servers in either direction, but I believe I may have found the problem.  Apparently my host is blocking port 445 which Windows wants to use to connect to the share and they will not unblock it.
    Is there a way to connect to the share through a different port?  
    To my knowledge, you cannot change the port. However, you can try disabling your security software for testing. If this fixes the problem then you need to adjust your security software configuration so that traffic on this port is not blocked or filtered.
    This posting is provided AS IS with no warranties or guarantees , and confers no rights.
    Ahmed MALEK
    My Website Link
    My Linkedin Profile
    My MVP Profile

  • Difference in results of queries on same data

    Hi all
    I have two tables, FURNITURE which contains transactions information of the customers who come for shoping to a store. IDNO column in the table shows ID of the customer, RECEIPTNO shows the receipt number of the customer. Each single visit will depict a single visit by any customer. D_CUSTOMER table contains customers information and demographics information. A single customer IDNO may have multiple entries in D_CUSTOMER table because a single customer may have multiple membership cards and hence multiple entries in D_CUSTOMER table.
    Now I want to know unique customers show did shoping during a time period and also their number of visits. So I am using following query to do this.
    select  COUNT(DISTINCT IDNO) AS UNIQ, COUNT(distinct RECEIPTNO) AS VISIT
    from FURNITURE
    where trandate_period_skey between 946 and 1126
    UNIQ         VISIT
    148269       265907
    Here we see that there are total 148269 distinct customer who visited total 265907 times for shoping of furniture. Each distinct receiptno shows a single visit.
    In my second query I simply involving D_CUSTOMER table to find out that how many visits were males and how many were females
    select GENDER, COUNT(DISTINCT A.IDNO),COUNT(distinct RECEIPTNO) AS VISIT
    from FURNITURE A,
    (SELECT IDNO, MAX(GENDER) AS GENDER FROM D_CUSTOMER WHERE MEMBERTYPE = 'PA' GROUP BY IDNO) b
    where TRANDATE_PERIOD_SKEY between 946 and 1126
    and a.IDNO = b.IDNO
    group by gender
    GENDER     UNIQ    VISIT
    F 103876 188573
    M 44393 77357
    Now here comes the problem. If we sum values under UNIQ column, total is 148269 (103876 Females and 44393 Males), which is same as the value in the result of first query. But, if we sum the values under VISIT column, 188573 visits by Females and 77357 visits by Males and total is 265930 which is different from the value of COUNT(DISTINCT RECEIPT) in first query because first query says total visits are 265907.
    I can't understand why I am seeing this difference. In my second query, the sum of values under VISIT column should be 265907
    Any one who can point out where are things going wrong and why there is difference in result?
    Salman

    Thanks rp0428. Actually first table already have data based on member with membertype='PA'.
    Any way, I have got the solution. Actually I had same receipt number issued to two different customers, one make and one female and hence while grouping, this type of receipts were being counted for both genders and hence total was greater during grouping.
    Case is closed.
    Salman

  • How do I join together these two queries?

    Hi I have these queries:
    select br_no, br_managersname from BRANCH order by br_managersname;
    select sum(rent_endkms-rent_startkms) as "TOTAL KMS TRAVELLED" from RENTAL group by BR_NO having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms)) from RENTAL group by BR_NO);
    They each output their own tables, but I wanna join them together so they output as one table. Unfortunately, I really suck at joining tables. Can anyone help?

    Hmm... Not enought information again... Any way, let me consider br_no as the key between the two query. In that case i came up with this.
    with query1
    as
    select br_no, br_managersname
    from BRANCH order by br_managersname
    query2
    as
    select br_no, sum(rent_endkms-rent_startkms) as total_kms_travelled
      from RENTAL
    group by BR_NO
    having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms))
                                               from RENTAL
                                              group by BR_NO)
    select q1.bar_no, q1.br_managersname, q2.total_kms_travelled
      from query1 q1
      join query2 q2
        on q1.br_no = q2.br_no

  • Re: ResultSet not returning same data

    Thanks to all who offered thoughts / advice on my post yesterday. For those interested here is what I found.
    The Problem -
    String data stored in MSSQL7 DB, transferred to MySQL4 DB, then pulled for an application did not match. Tests proved that the data IN the DB matched.
    What I found -
    Strings that were using unique chars such as French and German accent chars were NOT being returned correctly. It seems that when I call
    ResultSet.getString() using my SQL7 DB driver I would get a different result than when calling the same method in my MySQL4 Driver.
    To fix the problem I had to use
      String myString = new String(
                          ResultSet.getBytes()
                        );It seems that the DB driver was "assuming" what I wanted when using getString().
    Further tests proved that...
    MySQL DB Driver
    getString() == new String(getBytes()) true
    SQL7 Driver
    getString() == new String(getBytes()) false
    Just in case anyone was interested.
    Thanks for listening.
    ST

    In MySQL you can configure the charset used by the database. The default is "latin1", and if you have the correct data in your program, you can just use getString() and setString(). That setup handles strings with French and German accented characters, I know that because I have a program that does it.
    Perhaps your MS SQL configuration isn't working right? I don't have any experience on how to set that up.

  • Problem wih analysis authorization for two scenarios on same data provider

    Dear all,
    I am looking for a solution on the following authorization scenario (using the new analysis authorization). Unfortunately everything that I tried did not work out as expected:
    User A is allowed to manually access query 1 (based on cube A) with authorization on all sites A-Z
    The same user A shall get an email distribution automatically (derivation of the filter in the query out of the authorization) for query 2, which is as well based on cube A, but this time the authorization shall be limited only to site A.
    As both queries are based on the same infoobject (0PLANT) and the same infoprovider (0TCAIPROV) I always get the result for all sites A-Z. The 0TCAACTVT is in both cases 03 (display), so I have no chance to distinguish between reporting and email distribution.
    Probably the only chance would be to derive the values for the email distribution scenario not from the authorization directly, but using a customer exit to fill the filter - but I would prefer a "standard" solution...
    Any ideas??
    Thanks,
    Andreas

    Dear Andreas,
    Before give you an alternative for you problem, Iu2019d like to comment the combining authorization concept:
    http://help.sap.com/saphelp_nw70/helpdata/EN/46/98cd87f37d19ace10000000a11466f/frameset.htm
    For this reason I suggest you which combing restriction through authorization and query filter. For query 2 try to use in 0PLANT characteristic the single value u201Csite Au201D, this restriction give you only authorization for see this value.
    Otherwise, you have to use customer exit.
    I hope that alternative help you to find a solution,
    Luis

  • Two queries on same table in sender JDBC adapter

    Hi all..
    My requirement is as follows....
    query a table and fetch rows where column Error="true"
    If there are no records in the table satisfying the above condition ,i want to send a mail stating  that there are not records with error flag set to "true"
    But the problem is i wont get a message to PI if there are no records.
    If i write a query to get the count of records where column Error="true",Obviously the count would be zero. Using this message from database i can send a mail.
    Now please let me know if i can write both the queries in query SQL statement? if so howshould be the source structure?
    Thanks
    Ram..

    Hello ram,
                     As far as i know it is not possible to use two different SQL statements in the sender adapter, though you can try with the join statement.
    For further information refer this discussion
    [Multiple Select Possible?|How to call multiple SQL using the JDBC adapter;
    Regards,
    Prasanna

  • These two rams are same?

    Hi,i am new hereI am looking for a ram for my desktop , while browsing rams on amazon i found this Crucial CT51264BF160B ram and when i searched for this ram on Crucial's website and then tried to check if its compatible with my PC ,the product page turned into Crucial CT5297259. this happened more than twice so i am wondering if both products are same ? I hope you are getting what i mean.Sorry for bad English :3

    Hello,
    The two parts are basically the same. When you order online by system information, you are shown what we refer to as an “external” part number, in your case number CT5297259. It is a system specific number and is mapped exclusively to the HP 18-1106in All-in-One. The longer part number, CT51264BF160B, is the one that would you see printed on your module, and that is the actual module part number, or the "base" part number. There are other specifications to memory than the basic ones published on the site, and they sometimes requires us to filter out a certain build of a part for a specific system. The external part number can accomplish this, since we can build filters into them when necessary. Those filters are also the reason that we can only guarantee compatibility if you order by system; the external part number tells us which computer you are ordering for. If you order by specifications we don't know what model of computer you have, and that makes it impossible to guarantee compatibility.

  • Can these two queries be combined

    Is there a more eloquent way of joining the two tales to only
    get those records that have more than one record. Instead of
    writing two seperated queries, can one query achieve the
    results?

    Could this also have been solved with one query by just doing
    the following?
    <cfquery name="get_mult_posn" datasource="#dsn#">
    SELECT a.posn_id, a.pers_id, a.job_titl, frst_name,
    mid_name, last_name
    FROM posntable a, perstable b
    WHERE a.pers_id = b.pers_id
    </cfquery>

Maybe you are looking for

  • Can't burn with iTunes 8.2 or 9.0-- songs sound fuzzy

    Recently, when i bought my iPod Touch, I was instructed to update to iTunes 8.2; upon doing so, I found I could no longer burn CDs; the songs all sounded fuzzy. Today, I updated to iTunes 9.0, and the same thing happened: the songs all sounded fuzzy

  • Can't download files from my iPad to my windows Pc

    I'm unable to download from my Ipad to my windows PC Tried all support pages, with no luck. iTunes tells me i've got files on iCloud but cannot restore these

  • ArrayIndexOutOfBoundsException when executing query on dynamic VO

    I have some code inside a JSP template that dynamically creates a VO to select the column_names of a supplied unique index. <% UniqueKeyVO = myam.findViewObject("UniqueKeyVO"); newQueryClause = "SELECT column_name "+ "FROM all_ind_columns "+ "WHERE t

  • Binding variables in jDeveloper's SQL Worksheet

    I try to execute something like this is SQL Worksheet: variable myVar varchar2(10); execute :myVar:='ok'; print :myVar; I get ORA-00900: invalid SQL statement. In SQL plus this works just fine. Do I do something wrong or SQL Worksheet doesnot support

  • Failing to export to avi

    Hi, I'm trying to export an Apple Motion JPEG movie to avi. But everytime I try this it fails halfway, with an errorcode (-8969). Anyone have some clue to solve this?