Selecting from 2 different tables

is this possible?
i just want to select from two different tables in one select statement and they have the same WHERE clause

SELECT
  a.pkggrp,
  a.pkgtype,
  a.area,
  a.process,
  a.ww,
  count(a.ww) as LOTSGATED,
  sum(a.samplesize) as SUMSAMPLESIZE,
  sum(a.total_defects) as SUMTOTALDEFECTS,
  sum(case a.auditresult when 'pass' then 1 else 0 end) COUNTPASS,
  sum(case a.auditresult when 'fail' then 1 else 0 end) COUNTFAIL,
  case sum(case a.auditresult when 'fail' then 1 else 0 end)
    when 0 then 0
  else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / count(a.ww) * 100,2)
    end LRR,
  case sum(case a.auditresult when 'fail' then 1 else 0 end)
    when 0 then 0
  else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / sum(a.samplesize) * 1000000,0)
    end PPM,
  count(c.itrnum)
FROM
  t_prodproc_monitoring a, t_itr c
WHERE
  a.ww=c.ww
  and a.ww between 1 and 50
  and c.ww between 1 and 50
GROUP BY
  a.pkggrp,
  a.pkgtype,
  a.area,
  a.process,
  a.ww
ORDER BY
  a.pkggrp,
  a.pkgtype,
  a.area,
  a.process,
  a.ww ascthis gave me a
"c". "ww": invalid identifier

Similar Messages

  • Can't get table field from two different tables if named same

    select c.notes, o.notes
    from cusomters c, orders o
    :does not work in getting the RS.
    :if i change database to:
    select c.customer_notes, o.order_notes
    from cusomters c, orders o
    :then it works.
    :i make PURE DYNAMIC META SQL database
    applicaitons, and i need for abstract SQL tables.
    i have the same problem in getting
    the max values:
    select
    max(height),
    max(weight),
    max(age)
    from person_stats
    group by geographical_area

    When you select from 2 different tables you need to join them on some condition, otherwise it has no idea how to associate the 2 tables together.
    try select c.notes, o.notes from cusomters c, orders o where c.customer_id = o.customer.id or whatever the join fields are.
    For the group by I believe you have to include the field that you group by:
    select geopraphical_area, max(height), max(weight), max(age) from person_stats group by geographical_area
    give them a try
    Jamie

  • How to use dynamic select query which queries from 3 different table.

    Hi All,
    I am new to Toplink, i would like to use a named query to select some of the columns from 3 different tables with dynamic where clause.
    I have used the following lines. Please tell me how to get code for the dynamic where clause.
    First try :
    Vector objPersons = (Vector)session.executeQuery("findPersonByGlobalID",Person.class,vQueryArguments);
    The above method is not returning the vector or collection.
    Second Try:
    ReadAllQuery query = new ReadAllQuery(Person.class);
    query.useCollectionClass(LinkedList.class);
    LinkedList person = (LinkedList) session.executeQuery(query);
    The second try is returning the collection but, this fetches all the record from the table.
    1. How to query for range of records?
    2. How to query from multiple tables for some range. How to use dynamic range values ?
    Please reply with your answers or some pointers would help.
    Thanks and Regards,
    Vijay.B

    Hi,
    Did you try using a SQLCall ? It might be able to satisfy you requirements .. :-
    Employee employee = (Employee) session.executeSelectingCall(
        new SQLCall("SELECT * FROM EMPLOYEE WHERE EMP_ID = 44")
    );You can get more information here :-
    http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qrybas004.htm
    Regards,
    Sandeep

  • Selecting data from two different tables.

    Do we need to use join two tables with primary/foreign key while trying to use select statement for getting data from those to table.? If no who can i go about do it.

    872959 wrote:
    If i am using From clause to get data from two different tables, is it necessary that both tables have column of identical data in them.In general, they ought to (or you need to join in a third table that tells you how to map rows from one table to rows of the other table).
    It is not strictly necessary that there be any join condition between tables. If you don't provide a join condition, Oracle has to do a Cartesian product. That means that if there are n rows in one table and m rows in the other, the result set will have n * m rows. It is very rarely a good idea to write queries that do Cartesian products but it does occasionally happen.
    Justin

  • Resukt:Get number of rows from 3 different table...?

    Hi All,
    I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
    For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
    1. select count(1) from table_a where name = 'Ameet';
    1. select count(1) from table_b where name = 'Ameet';
    1. select count(1) from table_c where name = 'Ameet';
    Is it possible to write a single query to get result of all above 3 queries?
    result:
    table_a table_b table_c
    34 44 2

    One way:
    SELECT      (SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
    ,     (SELECT     COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
    FROM DUALIf you want the total:
    SELECT     SUM(CNT)
    FROM
         SELECT     COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_B WHERE name='Ameet'
         UNION ALL
         SELECT     COUNT(*) FROM TABLE_C WHERE name='Ameet'
    )

  • How to assign tasks in Approval Workflow to a set of users selected from a Lookup table

    Hi all,
    I am new to Project Server and I am using Project Server 2013 On premises deployement. Please help me on how to achieve the below scenario:
    I have a requirement where, the initial PDP will have 2 fields (Reviewers and Approvers), wherein the engineer himself will select who the reviewer and approver from the Lookup tables.
    Now I have to start task process with these selected people for approval.
    Say for example , engineer has selected Alice and Bob as 2 reviewers, then
    In the workflow I have :
                 Start Task process with
    Project Data: Reviewers (which is giving error as
    [System.ArgumentException: AssignedTo at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager
    bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) ]
    Then I tried logging the value of Project Data: Reviewers, It logged the value as Alice, Bob (which looks pretty good),
    Then I tried assigning only 1 person as Reviewer, then also I get the same error.
    So can anybody please tell me where I went wrong. Is it not possible to fetch the data from the values selected as Project Data from the Lookup tables ? If not then what is the workaround I can use to achieve this ?
    Thanks,
    Shanky

    Hi Paul,
    Yes I am using SP designer for Workflows. And yes, You were right, there was a mismatch in the names of AD account and the Lookup table, now with 1 person selected from the lookup table it is assigning the task properly. However with multiple selection,
    it is failing.
    As Robert mentioned, the fetched value is a text as "Alice, Bob", which makes 2 usernames as a single text. So when I try to assign a task to this group, which returns value as "Alice, Bob", workflow fails to find such AD user, as it
    is an invalid value.
    So is there any way I can seperate this out to form 2 different username ? I checked for string extraction function in th Workflow, but nothing helped me for this scenario.
    Any input will be helpful.
    Thanks,
    Shanky

  • Create one tables from 2 different tables

    Hi,
    How I can create one table from 2 different tables. Source tables have data and I want to include it in new table.
    I try this:
    create table NEW_ONE
    select * from OLD_ONE
    union
    select * from OLD_ONE2;
    But it didn't work correctly :/

    I don't have any error. This syntax create table NEW_ONE, but this table have columns only from OLD_ONE table :/ There aren't any column from OLD_ONE2 :/ Any suggestions?
    I don't forget about "as" in my query, only in this post.
    Edited by: tutus on Sep 8, 2008 6:36 AM

  • TSQL Help Counting from 2 different tables.

    I am trying to Count the number of items from 2 different Tables (A & B)
    But if I have a count in A and B I get 2 separate records. Id like them to be on the same record.
    Below is what I currently have.
    SELECT
    CUST.ID,
    CUST.ID_Name,
    COUNT(TABLEA.Item_ID) AS itemCount,
    0 AS itemCountShipped,
    0 AS itemCountTotal
    FROM TABLEA LEFT OUTER JOIN CUST ON TABLEA.ID = CUST.ID
    WHERE CUST.Customer_Type = 'I' OR CUST.Customer_Type = 'C'
    GROUP by CUST.ID,CUST.ID_Name
    UNION ALL
    SELECT
    CUST.ID,
    CUST.ID_Name,
    0 AS itemCount,
    COUNT(TABLEB.Item_ID) AS itemCountShipped,
    0 AS itemCountTotal
    FROM  TABLEB LEFT OUTER JOIN CUST ON TABLEB.ID = CUST.ID
    WHERE CUST.Customer_Type = 'I' OR CUST.Customer_Type = 'C'
    GROUP by CUST.ID,CUST.ID_Name
    ORDER BY CUST.ID_Name
    Ideally, I would like to have the all Counts to be calculated in the TSQL and have 1 record per ID.....and if there was a way to add those 2 up in the SQL that would be good too.  I currently process my data to give me the itemCountTotal.
    Any help would be greatly appreciated.

    On this portion "a.ItemCount, b.ItemCountShipped,"
    These fields are not on TABLEA or TABLEB, but if I remove the TABLE name from the front then TSQL says it cant find those fields.
    SELECT COALESCE(a.ID, B.ID) as ID, COALESCE(a.Name, b.Name) as Name,
    a.ItemCount, b.ItemCountShipped,
    COALESCE(a.ItemCount,0) + coalesce(b.ItemCountShipped,0) as itemCountTotal -- shipped + original count?

  • Creating LOV from 2 different tables

    I tried doing some searches on this, but haven't been able to find an answer. Can I create an LOV (to populate a select list) from two different tables? Both tables have the exact same column names/datatypes, just different data.
    Or if this isn't possible, should I just create a new table, and then do a union query to populate it with the values from both of these tables? Just wondering if anyone's had experience with this situation. Thanks!

    Hmm. That is weird. Wonder why it's not working for me.
    The SORT_ORDER column appears in both tables. I was hoping to be able to sort by the number value that appears in this column in both tables (could duplicate values in this table be causing an issue?).
    I even tried changing it to:
    SELECT DISPLAY_AS d1, CONTENT_KEY v1
    FROM SER_LISTS_JOB_TYPE
    WHERE ACTIVE = 'YES'
    UNION
    SELECT DISPLAY_AS d2, CONTENT_KEY v2
    FROM SER_LISTS_COMPANY_TYPE
    WHERE ACTIVE = 'YES'
    ORDER BY SORT_ORDERBut still get the same error message.
    Message was edited by:
    taneal
    OK. It appears the ORDER BY SORT_ORDER was causing the issue. I took it out and it worked. The only problem is that I have 1 duplicate entry, called "Other" that now appears twice in my LOV. Any thoughts on this? The value of CONTENT_KEY is different, but the value for DISPLAY_AS is the same. Is there anyway to pull out one of these?

  • 1 Graph from 2 different tables?

    I'm trying to build some bar charts with two matching data sets that are in two different tables (they're big data sets). I don't want to have to copy the specific data I want from each Table into a 3rd table just to build a chart with it. Can I use data from two different tables in the same chart? i.e. the data looks like this in the chart but is in two different tables?
    Table1 Table2
    Data 20 25
    Data 35 22
    Data 36 27...
    Does this question make sense? Thanks for any help.
    Message was edited by: Aaron Smith6
    Message was edited by: Aaron Smith6

    If I understand well the User Guide, we may chart datas from different tables BUT it works with rows of different tables, not with columns of different tables.
    +• To add a chart based on data in more than one table, first select a single table or contiguous range of cells and create a chart, then click Charts in the toolbar, and choose a chart type. Select the chart and hold down the Command key while clicking or dragging cells in another table to add their data to the chart.+
    Yvan KOENIG (from FRANCE vendredi 9 janvier 2009 21:37:41)

  • Select from view -v- table

    Hi Guys,
    I was just hoping to get your opinion on something.
    I have a procedure in Production that is taking longer and longer to finish and sticks on one certain section of code.
    The code is an INSERT into the main dimension table.
    This same procedure runs fine on TEST and the section of code completes an awful lot quicker.
    The traffic on Production is a lot heavier and there have been applications developed by people other than myself which SELECT from this dimension table. I'm assuming, based on the fact the code in Test and Production are identical, that this increased traffic could be eating up the bandwith and slowing the jobs.
    So, I was thinking - if I create Views and let the other applications hit the views as opposed to the main table, will this help speed it up. I did this before on a Teradata platform using a 'dirty read' which worked quite well but Oracle doesn't seem to offer this option.
    What do you guys think? Could this work or do I need to take a different approach.
    Thank You.

    GerardMcL wrote:
    I meant ordinary views.
    I was wondering if there was a way of putting some locking code in or asking for a dirty read that would speed up the SELECT from the table?There is no such thing as a dirty read with Oracle -- Teradata, SQL Server, Sybase, IBM, etc., have different locking architectures where reads can block write and writes can block reads, and that is not an issue with Oracle.
    If there's a query performance problem, which is what that will be if the SELECTs are slow, then if you could follow the following links, that will help diagnosis immensely:
    [How to Post A Tuning Request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    And:
    [When your Query takes too long|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    There is such as thing as stale reads, against Materialized Views, which are views that actually materialize and store the results of a query, and which then can subsequently be queried.

  • Sum two different columns from two different tables

    Can you select and sum two different columns, from two different tables in the same sql statement?
    i.e.
    table1
    Item----OnHand_Qty
    A--------10
    A--------15
    B--------10
    B--------10
    C--------20
    table2
    Item----Trx_Qty
    A--------2
    A--------4
    A--------6
    B--------1
    B--------1
    C--------4
    I'm looking for the following results from a query
    Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
    A--------25

    Like this?
    SQL> create table table1 (item,onhand_qty)
      2  as
      3  select 'A', 10 from dual union all
      4  select 'A', 15 from dual union all
      5  select 'B', 10 from dual union all
      6  select 'B', 10 from dual union all
      7  select 'C', 20 from dual union all
      8  select 'D', 30 from dual
      9  /
    Tabel is aangemaakt.
    SQL> create table table2 (item, trx_qty)
      2  as
      3  select 'A', 2 from dual union all
      4  select 'A', 4 from dual union all
      5  select 'A', 6 from dual union all
      6  select 'B', 1 from dual union all
      7  select 'B', 1 from dual union all
      8  select 'C', 4 from dual union all
      9  select 'E', 3 from dual
    10  /
    Tabel is aangemaakt.
    SQL> select nvl(t1.item,t2.item) item
      2       , t1.sum_onhand_qty
      3       , t2.sum_trx_qty
      4    from ( select item, sum(onhand_qty) sum_onhand_qty
      5             from table1
      6            group by item
      7         ) t1
      8         full outer join
      9         ( select item, sum(trx_qty) sum_trx_qty
    10             from table2
    11            group by item
    12         ) t2
    13         on (t1.item = t2.item)
    14  /
    I SUM_ONHAND_QTY SUM_TRX_QTY
    A             25          12
    B             20           2
    C             20           4
    E                          3
    D             30
    5 rijen zijn geselecteerd.Regards,
    Rob.

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • List rows with a certain value from a different table?

    Hi,
    I'm trying to list certain rows from a different table. Similar to the filter feature, kind of like a report.
    To be specific, I have 12 tables (Jan-Dec) with many entries each (as rows). Each row has a date, text and further data. Now I want to create an additional table that lists rows from the other tables that have a certain date.
    I would like to just enter that date in a header row cell so I can make a quick query. Using LOOKUP only shows the first row of that date. Is that even possible?

    Hi papalapapp,
    If you don't mind using a script, you're using Numbers 3, and all of your monthly tables are on the same sheet, then you could do something like this:
    Copy-paste script to Script Editor
    Enter date you want to filter on in the designated filterCell (here A1 of the Extract table). Make sure it is formatted exactly like the dates in the monthly tables.
    Clear any existing values from the Extract table, and make sure there are enough blank rows.
    Click the run button in Script Editor.
    SG
    property targetTable : "Extract"
    property filterCell : "A1"
    tell application "Numbers"
      tell document 1's active sheet
      set dateFilter to table targetTable's cell filterCell's formatted value
      --get all data in tables (excluding Extract table)
      set vv to {}
      repeat with t in tables
      if t's name is not targetTable then
      set vv to vv & t's rows's cells's formatted value
      end if
      end repeat
      --filter data
      set vvFilt to {}
      repeat with i from 1 to vv's length
      if vv's item i's item 1 is dateFilter then
      set vvFilt to vvFilt & {vv's item i}
      end if
      end repeat
      --write filtered data to table
      tell table targetTable
      repeat with r from 1 to (vvFilt's length)
      repeat with c from 1 to vvFilt's item 1's length
      set row (r + 1)'s cell c's value to vvFilt's item r's item c
      end repeat
      end repeat
      end tell
      end tell
    end tell

  • SELECTing from a large table vs small table

    I posted a question few months back about teh comparison between INSERTing to a large table vs small table ( fewer number of rows ), in terms of time taken.
    The general consensus seemed to be that it would be teh same, except for teh time taken to update the index ( which will be negligible ).
    1. But now, following teh same logic, I m confused why SELECTINg from a large table should be more time taking ("expensive" ) than SELECTing from a small table.
    ( SELECTing using an index )
    My understanding of how Oracle works internally is this :
    It will first locate the ROWID from teh B-Tree that stores the index.
    ( This operation is O(log N ) based on B-Tree )
    ROWID essentially contains teh file pointer offset of teh location of the data in teh disk.
    And Oracle simply reads teh data from teh location it deduced from ROWID.
    But then the only variable I see is searching teh B-Tree, which should take O(log N ) time for comparison ( N - number of rows )
    Am I correct above.
    2. Also I read that tables are partitioned for performance reasons. I read about various partiotion mechanisms. But cannot figure out how it can result in performance improvement.
    Can somebody please help

    user597961 wrote:
    I posted a question few months back about teh comparison between INSERTing to a large table vs small table ( fewer number of rows ), in terms of time taken.
    The general consensus seemed to be that it would be teh same, except for teh time taken to update the index ( which will be negligible ).
    1. But now, following teh same logic, I m confused why SELECTINg from a large table should be more time taking ("expensive" ) than SELECTing from a small table.
    ( SELECTing using an index )
    My understanding of how Oracle works internally is this :
    It will first locate the ROWID from teh B-Tree that stores the index.
    ( This operation is O(log N ) based on B-Tree )
    ROWID essentially contains teh file pointer offset of teh location of the data in teh disk.
    And Oracle simply reads teh data from teh location it deduced from ROWID.
    But then the only variable I see is searching teh B-Tree, which should take O(log N ) time for comparison ( N - number of rows )
    Am I correct above.
    2. Also I read that tables are partitioned for performance reasons. I read about various partiotion mechanisms. But cannot figure out how it can result in performance improvement.
    Can somebody please helpIt's not going to be that simple. Before your first step (locate ROWID from index), it will first evaluate various access plans - potentially thousands of them - and choose the one that it thinks will be best. This evaluation will be based on the number of rows it anticipates having to retrieve, whether or not all of the requested data can be retrived from the index alone (without even going to the data segment), etc. etc etc. For each consideration it makes, you start with "all else being equal". Then figure there will be dozens, if not hundreds or thousands of these "all else being equal". Then once the plan is selected and the rubber meets the road, we have to contend with the fact "all else is hardly ever equal".

Maybe you are looking for