Selecting columns from two table is slow but same

I am selecting 27 columns from two tables
which running for more than 30 minutes. but
if I select count(*) with the same query
except the columns it is coming in seconds.
Where is the error?

If you post
1) The table definitions for the underlying tables
2) The indexes that are on the tables
3) The two SQL statements you're running
4) The explain plan for both statements
we can probably be of some assistance.
My guess is that the count(*) is able to return much more quickly because the optimizer is able to use a significantly faster query plan that is based on an index which the longer-running query cannot utilize. Without the information I've requested, though, it's hard to do more than speculate.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

Similar Messages

  • Selecting data from two tables

    I am trying to select data from two tables.  The only problem that I am running into, is that i am only seeing results from my 'uploads' table.  there is also a record in documents where user = 1 that should show up.  here is my sql:
    $userIDNum = 1;
    $sql="Select *
    from uploads, documents
    WHERE uploads.user = documents.user AND uploads.user = $userIDNum
    ORDER BY uploads.title ASC, documents.title ASC";

    You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?

  • Select data from two tables...!

    HI Experts...!
    i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
    SELECT prps~pspnr
           prps~objnr
           prps~psphi
           proj~ernam
           proj~erdat
           proj~pspnr
    INTO  table itab   -
    itab is internal table
    FROM prps inner join proj
    WHERE pspnr in p_no and prpspsphi = projpspnr.
    but there is error in from clause ..please help me....
    Advance thanx....

    Hi,
    check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
    TABLES: prps, proj.
    TYPES:  BEGIN OF ty_test,
            pspnr LIKE prps-pspnr,
            objnr LIKE prps-objnr,
            psphi LIKE prps-psphi,
            ernam LIKE proj-ernam,
            erdat LIKE proj-erdat,
            END OF ty_test.
    DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
    SELECT-OPTIONS: p_no FOR prps-pspnr.
    SELECT  prps~pspnr
            prps~objnr
            prps~psphi
            proj~ernam
            proj~erdat
    *        proj~pspnr " No need for this you have selected this in
    *     the first line because it is commone so you only need to select from any one
            INTO TABLE itab
    FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr  )
    WHERE prps~pspnr IN p_no.
    Best Regards,
    Faisal
    Edited by: Rob Burbank on Dec 24, 2009 12:24 PM

  • How can I select columns from a table EMP, using Select statement?.

    Hi Friends,
    How can I select columns from a table EMP?.
    I want to select columns of EMP table, using select statement.
    Please reply me urgently.
    Shahzad

    Something like this:
    scott@DBA> select empno,ename,job from emp;
         EMPNO ENAME      JOB
          7369 SMITH      CLERK
          7499 ALLEN      SALESMAN
          7521 WARD       SALESMAN
          7566 JONES      MANAGER
          7654 MARTIN     SALESMAN
          7698 BLAKE      MANAGER
          7782 CLARK      MANAGER
          7788 SCOTT      ANALYST
          7839 KING       PRESIDENT
          7844 TURNER     SALESMAN
          7876 ADAMS      CLERK
          7900 JAMES      CLERK
          7902 FORD       ANALYST
          7934 MILLER     CLERK
    14 rows selected.Check the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
    Message was edited by:
    Delfino Nunez

  • SELECTing records from two tables. Set Operators, CASE, DECODE, ...

    Hi all,
    I have two tables:
    CRETE TABLE T1 (T1_COL1 NUMBER, T1_COL2 NUMBER)
    CRETE TABLE T2 (T2_COL1 NUMBER, T2_COL2 NUMBER)
    T1 may or may not have records. T2 always has records. There are two scenarios.
    Scenario 1:
    =======
    SELECT * FROM T1 returns five rows, and SELECT * FROM T2 returns 10 rows.
    Now I need the five rows from T1.
    Scenario 2:
    =======
    SELECT * FROM T1 returns zero rows, and SELECT * FROM T2 returns 10 rows.
    Now I need the 10 rows from T2.
    In other words, if records present in T1, I need them all. If not, I need records from T2.
    There are no common columns (for joins).
    Now need a single query to achive this. I tried set operators, CASE and DECODE. But I'm unable to solve it.
    Please help. Thanks in advance.

    Iniyavan wrote:
    Yes, Justin. I'm sure that this is the way it's modelled. I also find it's tough and odd.Are you sure it's the right way for that data to be modeled? I understand that's the way it is being modeled, but a data model change may be the best option.
    Is there any other way, which is simpler, without using RANK?That's the simplest option I can think of. You could also do something like
    SELECT t1_col1, t1_col2
      FROM (
        SELECT t1_col1, t1_col2, rownum rn
          FROM (
            SELECT t1_col1, t1_col2
              FROM (
                SELECT t1_col1, t1_col2, 1 tbl
                  FROM t1
                UNION ALL
                SELECT t2_col2, t2_col2, 2 tbl
                  FROM t2       
             ORDER BY tbl
    WHERE rn = 1I'm not sure that's any simpler...
    Justin

  • Can i select Records from two tables into an itab.

    Hi,
        Suppose that i have two tables spfli and sflight.
        Now i want the records from both the tables into a single internal table.
        If so please let me know how this can be done.
        itab should consist of all the columns in sflight and spfli.
    Regards,
    Sai

    Sai,
    Yes u can do it using JOINs.
    Use this link for ref
    http://www.sap-img.com/abap/inner-joins.htm
    INNER JOIN results are an intersection of the tables being joined where in only if both the tables havethe data the result is pused onto the result set.
    WHERE as in LEFT OUTR JOIN you can push the data of the LEF T table on the resultset even when the join condition is not met.
    The use is that you wantto have all the data that is there in left table and also the right table if the join condition is a success then right table fileds will have data else they are initial.
    OUTJOIN's are used in MAINTENANNCE VIEWS, HELP VIEWS .
    INNER JOINS are used DATABSE VIEWS.
    Inner Join:-
    SELECT pcarrid pconnid ffldate bbookid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( spfli AS p
    INNER JOIN sflight AS f ON pcarrid = fcarrid AND
    pconnid = fconnid )
    INNER JOIN sbook AS b ON bcarrid = fcarrid AND
    bconnid = fconnid AND
    bfldate = ffldate )
    WHERE p~cityfrom = 'FRANKFURT' AND
    p~cityto = 'NEW YORK' AND
    fseatsmax > fseatsocc.
    Left Outer Join
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND
    p~cityfrom = 'FRANKFURT'.
    Reward if helpful,
    Karthik

  • Select column from user.table

    Hi,
    I have 100 users. Each one has same table let's say tableA. I want a query that return back the value of a given column in that table for all users with their names. I thought about a join between dba_users (username) and that table. Basically I generate a script by this :
    select 'SELECT CULOMN FROM '||owner||'.'||TABLE_NAME||';' from all_tables where table_name='TABLEA';
    I execute the result script as sysdba.
    But when executed it does not show the name of each user. I mean we can not see which value belongs to whom.
    How can I do that ?
    many thanks before.
    Message was edited by:
    user522961

    Or perhaps you just want some dynamic SQL like this:
    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    CURSOR u IS
      3      SELECT username
      4      FROM   all_users
      5      ORDER BY username;
      6    v_cnt1 NUMBER;
      7    v_cnt2 NUMBER;
      8    v_tbl  VARCHAR2(30) := 'EMP';
      9  BEGIN
    10    FOR users IN u
    11    LOOP
    12      SELECT count(*)
    13      INTO   v_cnt1
    14      FROM   ALL_TABLES
    15      WHERE  owner = users.username
    16      AND    table_name = v_tbl;
    17      IF v_cnt1 > 0 THEN
    18        EXECUTE IMMEDIATE 'SELECT count(*) FROM '||users.username||'.'||v_tbl INTO v_cnt2;
    19        DBMS_OUTPUT.PUT_LINE('User: '||users.username||' Count on '||v_tbl||':'||v_cnt2);
    20      END IF;
    21    END LOOP;
    22* END;
    SQL> /
    User: FRED Count on EMP:27
    User: BOB Count on EMP:34
    PL/SQL procedure successfully completed.
    SQL>

  • Display columns from two tables without making join

    Hi,
    I need to perform currency conversion in the report.
    For eg:) Whatever the currency in ar_payment_schedules i want to
    convert it to INR equivalent.
    Following is the query to do this.
    select ps.invoice_currency_code Currency_B,
         decode(ps.invoice_currency_code, 'INR',ps.amount_due_original,
                   round(ps.amount_due_original*
                                  ps.exchange_rate,
                             curr.precision)
         from
              ar_payment_schedules     ps,
              fnd_currencies          curr
         where ps.customer_id          = '111'
         and curr.currency_code      = 'INR'
    When i do this in the Administration tool, the answers modules erroring out saying
    that no joins between ar_payment_schedules and fnd_currencies. But here join is
    not needed becuase fnd_currencies is filtered with INR and will return only
    one row. Without joining two tables how can i get the same results in Answers.
    thanks,
    Prasanna

    If it would return only one row then what is the need for the join (is it just for returning the precision?). Cant you just hard code the precision value instead of getting it from the table? Also you are doing a cartesian join, though the filters would take care of the final output this would result in a bad performance as your data starts scaling out. You need to find a key to join these 2 tables. If you do not have one, then just create a view with the cartesian join alone and then use that in your report.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • How do you Select data from two tables with similar data amd merge the output together.

    I have two Tables containing Sales Data. I want to read the Table a sort by date and accumulate dollars by order date. Then I want to read the second table and accumulate these dollar amounts by date and then merge the records together so that I gave 1 row
    with amounts for type A and amounts for type b.
    Here are the tables I am looking at.
    Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
              ,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
              ,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
              ,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
              ,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
              ,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
              ,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
              ,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
    from [PRODUCTION].dbo.Job As J
    union all
    Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
              ,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
              ,Sum(Case when Sales_Code = '5-Day'     then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
              ,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
              ,Sum(Case when Sales_Code = ''          then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
              ,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
              ,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
              ,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
    from [PRODUCTION].dbo.SO_Detail As SD
    Inner Join [PRODUCTION].dbo.SO_Header As SH
        on SD.Sales_Order = SH.Sales_Order
    Group by J.Order_Date
    Order by J.Order_Date Desc
    Looking for output like
    Order Date   Job Comm   Job AUto   Job Fixed    SO Comm  SO AUto  SO Fixed
    Mar-11-2014    100.00     250.00       50.00     200.00   300.00    400.00
    Mar-10-2014    500.00     340.00        0.00     110.00   400.00    500.00
    Mar-09-2014    600.00     333.00       56.00     210.00   500.00    300.00
    Thanks for your help
    SWProduction

    Seeing the output it looks like what you need is this
    select COALESCE(p.[Order Date],q.[Order Date]) AS [Order Date],
    COALESCE([Job Comm],0) AS [Job Comm],
    COALESCE([Job AUto],0) AS [Job AUto],COALESCE([Job Fixed],0) AS [Job Fixed],COALESCE([SO Comm],0) AS [SO Comm],COALESCE([SO AUto],0) AS [SO AUto],COALESCE([SO Fixed],0) AS [SO Fixed]
    from
    Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
    ,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
    ,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
    ,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
    ,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
    ,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
    ,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
    ,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
    from [PRODUCTION].dbo.Job As J
    )p
    full join
    Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
    ,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
    ,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
    ,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
    ,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
    ,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
    ,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
    ,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
    from [PRODUCTION].dbo.SO_Detail As SD
    Inner Join [PRODUCTION].dbo.SO_Header As SH
    on SD.Sales_Order = SH.Sales_Order
    Group by J.Order_Date
    )q
    on p.[Order Date] = q.[Order Date]
    Order by COALESCE(p.[Order Date],q.[Order Date]) Desc
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to find diffrence in columns from two tables

    Hello,
    I have table TABLE1 and TABLE2 with same columns. One of the columns in both tables is ID
    Now there are records in table TABLE1 with ID=1
    and in table TABLE 2 with ID=-1
    Now I want to find if there are any column differing in values in tables TABLE1 for ID=1(for TABLE1) and TABLE2 for ID = -1 (for TABLE2)
    What is the best way to find the diffrence?
    Thanks in advance.

    Hello Subhash,
    Why don't you try NOT EXISTS functionality? Its quite performance effective too.
    select * from table1
    where NOT EXISTS
    (select 1 from table 2
    where table1.ID = table2.ID)
    UNION
    select * from table2
    where NOT EXISTS
    (select 1 from table 2
    where table1.ID = table2.ID)You can go for UNION if required, or else you can use them separately.

  • How to find common columns from two tables

    regards

    812809 wrote:
    regardsHi,
    Use User_tab_cols view to extract the result.
    Try
    SQL> create table test3(id number(10),name varchar2(10));
    Table created.
    SQL> create table test4(id number(20),addr varchar2(200));
    Table created.Now query user_tab_cols
    SQL> select column_name from user_tab_cols where table_name='TEST3'
      2  intersect
      3  select column_name from user_tab_cols where table_name='TEST4'
      4  /
    COLUMN_NAME
    IDHope this helps
    Regards,
    Achyut
    Ps-> Mark as Complete/Answered if it meets your requirement

  • How can I get the selected rows from two ALV grids at the same time?

    I have a program that uses two ALV grids in one dialog screen. I'm using the OO ALV model (SALV* classes).
    The user can select any number of rows from each grid. Then, when a toolbar pushbutton is pressed, I'd have to retrieve the selected rows from both grids and start some processing with these rows.
    It is no problem to assign event handlers to both grids, and use the CL_SALV_TABLE->GET_SELECTIONS and CL_SALV_SELECTIONS->GET_SELECTED_ROWS methods to find out which rows were marked by the user. Trouble is, this only works when I raise an event in each grid separately, for instance via an own function that I added to the grid's toolbar. So, I can only see the selected rows of the same grid where such an event was raised.
    If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.
    As it is right now, I can have an own button in both grid's toolbar, select the rows, click on the extra button in each grid (this will tell me what entries were selected per grid). Then, I'd have to click on a third button (the one in the dialog screen's toolbar), and process the selected rows from both grids.
    How can I select the rows, then click on just one button, and process the marked entries from both grids?
    Is it somehow possible to raise an event belonging to each grid programmatically, so that then the corresponding CL_SALV_SELECTIONS->GET_SELECTED_ROWS will work?
    Thanks.

    Hello Tamas ,
    If I try to do this in the PBO of the dialog screen (that contains the two grids), the result of CL_SALV_SELECTIONS->GET_SELECTED_ROWS will be empty, as the program does not recognize the marked entries in the grids. Also, an event for grid1 does not see the selected rows from grid2 either.--->
    is it possible to  have a check box in each grid  & get the selected lines in PAI of the screen ?
    regards
    prabhu

  • How to select columns from internal table using 'GUI_DOWNLOAD' ?

    Hi,
    i am running a report & the fields for output is saved in an internal table which has as many as 10 fields. But I want to select only a few fields for output. There is a option COL_SELECT in function 'GUI_DOWNLOAD'. How to use it. If possible with example.

    Hai VijayKumar
    Try with the following code
    tables : mara.
    data : begin of it_mara occurs 0,
           matnr like mara-matnr,
           mbrsh like mara-mbrsh,
           mtart like mara-mtart,
           meins like mara-meins,
           end of it_mara.
    parameters : P_mtart like mara-mtart default 'ROH'.
    start-of-selection.
    perform select_data.
    perform download_data.
    *&      Form  select_data
          text
    -->  p1        text
    <--  p2        text
    FORM select_data .
    select
          matnr
          mbrsh
          mtart
          meins
          from mara into table it_mara
          where mtart = p_mtart.
    ENDFORM.                    " select_data
    *&      Form  download_data
          text
    -->  p1        text
    <--  p2        text
    FORM download_data .
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                        = 'c:\down.txt'
        FILETYPE                        = 'ASC'
        COL_SELECT                      = 'X'
        COL_SELECT_MASK                 = 'X XX'
      TABLES
        DATA_TAB                        = it_mara.
      IF SY-SUBRC = 0.
        SORT IT_MARA BY MATNR.
      ENDIF.
    ENDFORM.                    " download_data
    Thanks & Regards
    Sreenivasulu P

  • Select fields from two tables

    Query works fine when I query one table. When I add the
    second it generates the following error.
    -1:[Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Could not find
    file 'C:\CFusionMX7\db\slserver54\logging\mob.mdb'
    See code.
    Thank you

    Also does Access understand this way of joining tables? I do
    not
    believe I have very seen Access SQL that did not use INNER
    JOIN syntax.
    I.E.
    FROM mob_user JOIN mob_user_type ON mob_user.user_type_id =
    mob_user_type.user_type_id

  • How to select columns in a table by their column id and not the column name

    Hello,
    How do you select columns from a table based on their column_id.
    I have create a view
    but other than Select * , i cant now select one just one column from it
    the view as follow:
    create view count_student as
    select a.acode "acode",aname "Activity Name",count(ae.acode) "Number of student joined"
    from aenrol ae, activity a
    where a.acode= ae.acode
    group by a.acode,aname;

    The issue is that you have decided to use quoted column names. A pretty horrible idea (mostly for the reasons that you are now finding).
    Re-create the view and get rid of the silly double quotes.

Maybe you are looking for