Avoid distinct clause in the query

hi i have a query from a single table using distinct clause and has columns (a,b,c,d,e,f,g,h,i)
eg: select distinct a,b ,c,d from table
where a<>0 and b<>0 and c<>0 and d<>0 and e=o and f=0 and g=0 and h=0 and i=0 ;
when i see the execution plan with out distinct... it performs a bit faster.
how do i remove distinct clause and make the query perform better
this particular query is used as inline view in my vieiw . it is used in from clause .
please suggest
second question.... iam getting bitmap index to rowid conversion ...is this good? does it hamper performance . how to avoid this?
regards
raj
Edited by: raj_fresher on Jul 17, 2009 7:48 AM

Hi Raj
what is e in the query ?It is the column name you provided yourself in your own unformatted example.
After 400+ posts I thought you would understand that it's not that hard to put this exact tag => (yes, 6 characters, 4 letters between 2 curly brackets) before and after your code examples or sample data or explain plans.
That way you maintain formatting and improve readability for us poor readers by magnitudes.
But, I'm sure you'll succeed as well as all the others who can.
I always look on the bright side.
Example:
Earlier this week another Raj also finally got enlightened about it, and his life has since then changed forever!
+He drives a Bentley now, you know+ ;)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Suppress "Distinct" Clause from Answers Query

    Hello All:
    How can I suppress the "Distinct" clause that the BI Server issues to the Oracle Database?
    For Ex:
    I have a customer Table with FirstName and LastName as columns. If I Query FirstName and LastName in Answers, BI server sends a Query like this:
    select distinct T8944.fname as c1,
    T8944.lname as c2
    from
    CUSTOMER T8944
    order by c1, c2
    This will suppress customers having the same name even if their customer Id is different. I want their names included also.
    I would appreciate your help.
    Thanks
    rkingmdu

    AFAIK, there's no config setting or so to prevent this implicit grouping. What you can do though is to add the customer Id ot the report and make the column hidden (Column Format - Hide).
    Hth,
    Chris
    Edited by: Christian Berg on Sep 25, 2008 4:39 PM:
    Or what Matt said ;-) Should type faster...

  • Performance hit using "where" clause in the query

    Hi All,
    I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
    1. SELECT * FROM Employee
    2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
    There is no difference in Query Execution Time for both queries.
    Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
    Rows returned are more in first case as compared to second case.(ratio - 1:4)
    Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
    Does anybody know the reason of unexpected time difference for the business logic in the second case?

    Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
    Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
    First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
    Second, you may need your DBA to enable autotracing, if it's not already:
    http://asktom.oracle.com/~tkyte/article1/autotrace.html
    http://www.samoratech.com/tips/swenableautotrace.htm
    Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
    For example:
    SQL> set autotrace on
    SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
      COUNT(*)
            11
    Execution Plan
    Plan hash value: 2983758974
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            |     1 |     4 |     1   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE   |            |     1 |     4 |            |          |
    |*  2 |   INDEX RANGE SCAN| TICKET_N10 |    12 |    48 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
    Statistics
              0  recursive calls
              0  db block gets
              1  consistent gets
              0  physical reads
              0  redo size
            515  bytes sent via SQL*Net to client
            469  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
    the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
    If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
    since sql*plus is not a JDBC thing...
    Oh, and sql*plus can also give you easier access to timing information, with "set timing on".

  • Where() clause returning "The query specified in the URI is not valid..."

    I have a .Net mobile service.
    Calling this:
    https://qserv.azure-mobile.net/tables/items?$filter=(company%20eq%20%27987af3f9-8d44-4a9d-8be2-7e0567287106%27)
    Returns:
    {"message":"The query specified in the URI is not valid. Could not find a property named 'company' on type 'Default.<>f__AnonymousType2_3OfString_String_Double'."}
    The field name in the "items" entity model is "company" and on the database is "company_Id", neither will work.Using http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.2.5.min.jsWhat is wrong?
    Regards

    I see. Now works. So it would be like doing "SELECT ITEM,CATEGORY,COUNTRY, FROM TABLE WHERE CATEGORY='toy' AND COUNTRY='US'"
    All rows will contain the "CATEGORY" and "COUNTRY" fields (or more), which is kind of redundant and bandwidth consuming.
    Hope MS can change this.
    Regards

  • GROUP BY and DISTINCT clause in single query

    Hi All,
    I have this query:
    SELECT studyid,baseline_no,trans_date, min(trunc(compass_date)),drug_related_yn
    FROM cp_bdr_trigger_tbl cbtt
    WHERE NOT EXISTS (SELECT 1
    FROM cp_patient_info_tbl
    WHERE studyid = cbtt.studyid
    AND baseline_no = cbtt.baseline_no)               
    AND studyid = '0431-020'
         GROUP BY BASELINE_NO,STUDYID,DRUG_RELATED_YN;
    The o/p of this query has around 20 rows with same studyid and distinct baseline_no.
    Now I want to select the data all to be distinct by limiting it somehow by GROUP BY clause.
    Is this possible?
    I mean grouping should be done in such a way that it should return distinct values only...
    The o/p of this query is input to other query for insertion in some table.
    * there is a Unique index in the target table on studyid+basline_no combination so the combination has to be unique*
    Thanks,
    Aashish S.

    The GROUP BY is in a way an implied DISTINCT because it will return ONE record for each of the columns identified in the GROUP BY clause.
    Either way your requirements aren't very clear. If you can please post the following we may be able to help:
    1. Oracle version (e.g. 10.2.0.4)
    2. CREATE / INSERT statements with sample data
    3. Expected output
    4. Use \ tags (surround #2 and #3 in these tags)
    5. Explanation of logic in achieving #3.
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to get distinct data if the query contains a column with Long Datatype?

    How can we select distinct records based on a LOng column

    From the Oracle 9i SQL Reference:
    LONG columns cannot appear in certain parts of SQL statements:
    n GROUP BY clauses, ORDER BY clauses, or CONNECT BY clauses or with the
    DISTINCT operator in SELECT statements
    n The UNIQUE operator of a SELECT statement
    n The column list of a CREATE CLUSTER statement
    n The CLUSTER clause of a CREATE MATERIALIZED VIEW statement
    n SQL built-in functions, expressions, or conditions
    n SELECT lists of queries containing GROUP BY clauses
    n SELECT lists of subqueries or queries combined by the UNION, INTERSECT, or
    MINUS set operators
    n SELECT lists of CREATE TABLE ... AS SELECT statements
    n ALTER TABLE ... MOVE statements
    n SELECT lists in subqueries in INSERT statements

  • Using "in" clause in the query in Database control

    Hi,
    I have a database control and need to fire an update query to update a set of rows based on a list of values as input
    Like below
    update tablename
    set column1="value1"
    where column2 in (.......)
    I need to pass a list of values for this query where column2 is a NUMBER field in Oracle DB.
    can anyone help me how to go about passing this list of values?
    Help is appreciated.
    Thanks

    You may build the comma-separated list in Java and use " {sql: ...} " in your query: http://e-docs.bea.com/workshop/docs81/doc/en/workshop/java-class/com/bea/control/DatabaseControl.html (sorry, I can't find the documentation for WLI 9.2).

  • Tunning the Query with Distinct Clause

    Hi All,
    I have the below query that returns 28113657 records
    select src_Wc_id, osp_id, src_osp_id
    from osp_complements o1
    where exists (select 1 from wc_crossref wc
                        where wc.src_wc_id = o1.SRC_WC_ID
                        and wc.state = 'CA')
    This query executes within a second...
    But when i include a DISTINCT clause in the select statement, it takes more time ... (more than 20 mins)
    I am trying to get it tunned. Please advice me with your knowledge to get it done
    Thanks for your time
    Kannan.

    Retrieving distinct rows requires a sort of all returned rows. 20 - 3 = ~17 mins for sorting 28 mln rows looks too much. You need to tune your instance in order to speed up sort operation. The amount of memory dedicated to sorts is controlled by PGA_AGGREGATE_TARGET parameter. If it's set to 0 (not recommended) then SORT_AREA_SIZE is used. The process of PGA tuning is quite complex and described in PGA Memory Management chapter of Performance Tuning Guide.
    There is a workaround which allows to bypass sort operation, but it requires proper index and proper access by that index. The idea is that rows rertrieved via index are automatically ordered by indexed columns. If that and only that columns (possibly - in the same order as in the index, I don't know) are selected using DISTINCT then sort is not actually performed. Rows are already sorted due to access via index.
    Hope this will help you.
    Regards,
    Dima

  • OPEN CURSOR using a WITH clause in the select query

    Hi,
    I am using Oracle 9i. I have a requirement where I have a REFCURSOR as an OUT parameter for my procedure. I have declared the TYPE and created the procedure.
    In the procedure, I am using OPEN <cursor_name> FOR <query>;
    Ideally this works in most of the cases that I have tried earlier. However, in the current case I am using a WITH clause in my query to get the results.
    I need help in understanding if the above mentioned syntax would not allow me to use the WITH clause in the query.

    What error do you get , seems to work ok for me on 10g
    SQL> begin
      2  open :cv for 'with x as (select * from emp)  select * from x';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :cv
         EMPNO
    ENAME
    JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7521
    WARD
    SALESMAN        7698 22-FEB-81       1250        500         30
          7566
    JONES
    MANAGER         7839 02-APR-81       2975                    20
         EMPNO

  • Distinct Clause missing on "Primary Key"

    In our implementation, we have views and tables mixed physical Schema. For the views, obviously, they do not have to have 1 column as PK, but have a combination of columns to uniquely identify a record. Now when we use some of the views as dimension in our physical layer to do a join, it will automatically mark that joined column in the view as a "key" column, which makes sense.
    Now, when we expose the very same column to the presentation, and then, do a query on that, it did not give use a distinct value of that column, instead, it give you 1 row per line. If I make a request by using columns with PK column from the same dimension table, it will not have a "Distnct" in the select statement , But if I put the PK column with other columns from a Fact table, it is then showing a "Distinct" clause in the select statement. In our situation, we need to have a distinct clause in the select statement, even there is no fact column involved.

    By definition your key column(s) defined in the Physical and Logical models must be unique. If you have multiple rows returned for your key when selecting from just the dimension table then your key is incorrect.
    If you are saying when you join to the fact you see multiple rows, then check you have set your aggregate functions correctly on your fact measures. ie. SUM/COUNT etc...
    Hope this helps.

  • Regarding setting additional clauses to  the Standadr VO

    Hi,
    I have a standard VO. I want to append certain conditions to the query of the VO.
    The additional clause begins with 'minus'.
    I have read something in this forum itself about getting the existing query from the VO and then appending the clauses to the query and adding the query back to the VO.
    Please give me your valuable inputs regarding this issue.
    Thanks,
    Priya

    Follow the thread Regarding setting a where clause dynamically for a standard VO
    --Shiv                                                                                                                                                                                                       

  • How to remove the OR clause in this query?

    Hello Everyone,
    I have this query where i have a lot of joins and in the where clause there is a ISNULL and conditions based on OR clause.
    How to remove the use of the OR clause which may cause performance problems? Can anyone suggest a method to remove the OR clause?
    select RS.PLANNEDSTART,
    OD.ESTSHIPDATE
    FROM TABLE1 RS(NOLOCK)
         INNER JOIN TABLE2 SS(NOLOCK)
         ON RS.ID1             = SS.ID1
         INNER JOIN TABLE3 AM(NOLOCK)
         ON AM.KEYID        = SS.KEYID
         INNER JOIN TABLE4 OD(NOLOCK)
         ON SS.KEYID= OD.KEYID
        INNER JOIN TABLE 8 DR
       ON
    WHERE              (isnull(RS.DATE1,'1970-01-01 00:00:00.000') ='1970-01-01 00:00:00.000'
                     AND OD.DATE1 between @Beginning_Route_Date and @Ending_Route_Date)
                 OR
                 RS.DATE1!='1970-01-01 00:00:00.000'
                   AND RS.DATE1 BETWEEN  @Beginning_Route_Date and @Ending_Route_Date)              
    Regards
    Gautam S
    Gautam S

    this is one way avoiding OR clause
    WHERE CASE WHEN isnull(RS.DATE1,'1970-01-01 00:00:00.000') ='1970-01-01 00:00:00.000'
    THEN OD.DATE1 ELSE RS.DATE1 END between @Beginning_Route_Date and @Ending_Route_Date)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Problem with performance of a query having order by, distinct clause

    Hi,
    I have a problem with queries having order by, distinct clause.
    While its executing its taking lot of time. With DBMS_PROFILER identified the queries taking long time.
    The table is having approximately 70 million rows.
    Problem -1
    select * from table_name order by col1;
    select distinct col1,col2 from table_name;
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.
    Solution1:
    Max parallel servers is 8.
    select /* + parallel(table_name,8) */ * from table_name order by col1;
    select /* + parallel(table_name,8) */ distinct col1, col2 from table_name ;
    Solution-2:
    select /* + first_rows */ * from table_name order by col1;
    select /* + first_rows */ distinct col1, col2 from table_name ;
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';
    Index created on col1 and col2.
    As we no that not equal won't use index as it is a composite index it should use the lead column. but its not using the index.
    Should i forcibly use index with hint or suggest me better solution.
    Any help really appreciated.
    Thanks in advance

    unique wrote:
    The table is having approximately 70 million rows.
    select * from table_name order by col1;Do you really want 70,000,000 rows from your table without any restrictions ? And furthermore ordered output ? I honestly understand the slowness of that query.
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.Who knows if you choosed the right solution. I would suggest to reconsider your query and the need of 70,000,000 returned rows.
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';Please, provide the explain plan, eventually the tkprof output could also help. And tables descirption AND indexes description.
    And OS and Oracle version.
    Nicolas.

  • Creating a where clause in the LOV query box

    Hi guys is any able to help me with this one
    i have a page in my app where there is a LOV drop down now the values for this drop down comes from a table that looks like this
    users_for _form_TBL
    E_MAIL
    Vendor
    [email protected]
    oracle
    [email protected]
    sap
    [email protected]
    IBM
    [email protected]
    Oracle
    [email protected]
    intergraph
    So my syntax for the LOV i mentioned looks like this
    select VENDOR as display_value, VENDOR as return_value
      from form_user_tab where E_MAIL = :APP_USER
    order by 1 ;
    so if [email protected] logs onto the app and has to make a selection on the LOV it would only display the vendors relative to his E_MAIL like oracle ,sap, IBM then he hits the submit button on the page then the vendor that he selected is inserted into another table .What i did on the insert table was create a trigger that after a vendor is inserted the trigger inserts a 1 into a column called assessed .
    What i did after this was add a select in the where clause of the LOV so that it would check in the insert table if that vendor had been chosen before and not display it again to be selected  my syntax the second time around in the SQL query box was
    select VENDOR as display_value, VENDOR as return_value
      from users_for _form_TBL where E_MAIL = :APP_USER
    and (select 'vendor' , 'ASSESSD' from inserted _tbl_imp is null);
    order by 1 ;
    But im getting an error any ideas guys .Thank you

    Hay man thanks for that info on the Tom Kyte Blog 
    --(the code you gave me )
    select 
        u.vendor display_value 
      , u.vendor return_value
    from 
        users_for_form_tbl u 
    where 
        u.e_mail = :app_user 
    and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor) 
    order by 
        u.vendor 
    --(After the error i tried )Then when i got the error i try'd using 'or exists'  like this
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor) 
                          or exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
    order by 
        u.vendor 
    But the all the vendors that where in the  same in the insert table came up in the drop down list  example is oracle was assessed before then only oracle would appear in the drop down list  and if it was assessed 3 times it would come up 3 times
    --Then i tried to select where 'Assessed' is null   ('Assessed' is a column in the insert table  which i created a trigger on to insert 1 in the 'ASSESSED' column  when a vendor is begin assessed  )  
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select 'ASSESSED' from inserted_tbl_imp i where 'ASSESSED' is null ) 
    order by 
        u.vendor 
    This try didnt return any vendors at all
    --Then i tried distinct
    --(code)
    where 
        u.e_mail = :app_user 
    and not exists (select distinct 'VENDOR',  from inserted_tbl_imp i where u.vendor = i.vendor) 
    order by 
        u.vendor 
    This gave me a LOV ERROR
    This is what i have tried so far there where others syntax's i tried last night as well  but most of them came back as errors . Thanks again for you time and help  fac586  

  • How to put distinct in the query

    Hi all,
    How to put distinct in the query.I checked in RPD , Distinct supported is already available. I marked the distinct check box in advance option still then i'm not getting distinct in the query.
    any idea , please help...

    In the RPD i have join between base table and view .i'm selecting 2 columns one from base table and other from view . which gives cartesian product . to avoid that i want to put distinct . I'm not using any measure . I'm taking direct columns.
    I'm getting distinct keyword if i'm accessing the report directly . but when i'm accessing it from dashboard in the back end while preparing the query it's writing distinct but the actual query which is sending to db does not have distinct.
    ==================================================
    RqList distinct
    VW_SCNR_114000074_TA_DATA.Match Identifier as c1 GB,
    VW_SCNR_114000074_TA_DATA.Tot Trans Amt as c2 GB,
    VW_SCNR_114000074_TA_DATA.Tot Trans Ct as c3 GB,
    case when VW_SCNR_114000074_TA_DATA.Alert Quality Code = '1' then 'Productive' when VW_SCNR_114000074_TA_DATA.Alert Quality Code = '2' then 'Non Productive' else 'Indeterminate' end as c4 GB,
    VW_SCNR_114000074_TA_DATA.Batch Identifier as c5 GB
    DetailFilter: Alert TA Data.Run Id > 0 and Alert Scenarios.Scenario Name = 'ScnroName' and Alert TA Data.Batch Id > 0
    OrderBy: c4 desc
    =================================================
    -------------------- Sending query to database named KYC1.1DEV-179 (id: <<16315>>):
    select T353.BATCH_ID as c1,
    case when T353.QLTY_RTG_CD = '1' then 'Productive' when T353.QLTY_RTG_CD = '2' then 'Non Productive' else 'Indeterminate' end as c2,
    T353.TOT_TRXN_CT as c3,
    T353.TOT_TRXN_AM as c4,
    T353.BREAK_ID as c5,
    T117.SCNRO_NM as c6
    from
    KDD_SCNRO T117,
    KDD_TA_DATA T130,
    KDD_TSHLD_SET T171,
    VW_SCNR_114000074_TA_DATA T353
    where ( T117.SCNRO_ID = T130.SCNRO_ID and T117.SCNRO_ID = T171.SCNRO_ID and T130.SCNRO_ID = T171.SCNRO_ID and T130.SCNRO_ID = T353.SCNRO_ID and T130.TSHLD_SET_ID = T171.TSHLD_SET_ID and T171.SCNRO_ID = T353.SCNRO_ID and T171.TSHLD_SET_ID = T353.TSHLD_SET_ID and 0 < T130.BATCH_ID and 0 < T130.RUN_ID )

Maybe you are looking for

  • Saving as PDF: fonts look crappy?

    I have a small test .psd image with just one piece of text. When I save this as .pdf from Photoshop CS4 (using Save As and choose Photoshop PDF format) and open the .pdf with Acrobat 9, the font looks pretty messed up. Here's an example of what I mea

  • Windows with Mac-basic questions

    I had been using a my Mac for work; then switched to my notebook PC (Dell, D630) . That becuase I had to use outlook and ACT and a few other programs that are work related. I would like to update my MacBook to Leopard, and use boot-camp to run Window

  • Cannot open ports!

    Hello, I thought I should come here as a last resort so here I go... I have been using a WRT54G for quite some time, I find it does the job smoothly and quickly... However, I cannot open ports (or at least a specific one)... I am looking to host a ga

  • Lost ical data when upgraded to maverick

    I've upgraded from Snow Leopard to Mavericks and now find I have none of my icalendar data.   Can anybody help?  I do have the Time Machine Backup but don't know how to retrieve ical data from it. Thanks for any help!

  • Default Deployment profile in ADF

    We are in the process of creating EAR file for uat/production , when i created ear file using default Deployment profile in Jdev(Studio Edition Version 11.1.1.6.2 ), Jdev also placing following files META-INF/application.xml META-INF/cwallet.sso META