Join returns duplicate rows

Hi All,
I am joining 3 tables:OWOR, WOR1 and IBT1. Following is the query:
SELECT OWOR.DOCNUM, OWOR.ITEMCODE, OWOR.CLOSEDATE, OWOR.DOCENTRY,
WOR1.ISSUEDQTY, WOR1.DOCENTRY,
IBT1.QUANTITY, IBT1.BATCHNUM
FROM OWOR INNER JOIN WOR1 ON OWOR.DOCENTRY = WOR1.DOCENTRY
IBT1 INNER JOIN ON OWOR.ITEMCODE = IBT1.ITEMCODE
WHERE OWOR.CLOSEDATE ='[%0]' AND OWOR.DOCNUM = CONVERT(INT,IBT1.BATCNUM)
O/P:
10  100  19.03.11  20   15   30    10
10  100  19.03.11  20   15   14    10
20  121  19.03.11  25   31     5    25
20  121  19.03.11  25   31   10    25
20  121  19.03.11  25   28     5    25
20  121  19.03.11  25   28   10    25
Note: I have tried Grouping on OWOR.DOCNUM, WOR1.DOCENTRY, also tried
Suppress with the combination of Prevoius
and Next. But could not succeed always the running totals of WOR1.ISSUEDQTY
and IBT1.QUANTITY are getting messed
up.
Please let me know if you have any suggestions.
Thanks,
Vineela.

Hi Ian,
Sorry for the delay in replying, was stuck due to some Internet connectivity issues. Coming to the problem, I solved it myself, by changing the Running Total conditions when to evaluate and and when to reset. And my required O/P was:
Required O/P:
10 100 19.03.11 20 15 44 10
20 121 19.03.11 25 59 15 25
Thanx for your reply,
Vineela.

Similar Messages

  • Returning Duplicate Rows

    Hi. I'm working on this query, and I'm having problems. When I add an inner join, I start getting multiple rows returned.
    What I want returned is ONLY the first row below, but I'm instead getting both rows (which are identical).
    SALESMAN_NO | CUSTOMER_NO | ORDER | SALES | COGS | MARGIN
    97 | 1306969000 | 00477023 | 517.40 | 298.20 | 219.18
    97 | 1306969000 | 00477023 | 517.40 | 298.20 | 219.18
    Here's my query. And when I add the inner joins, I get the 2nd row above. If I run the SAME query without the inner joins, I get the 1 and only 1 row - which is what I'm trying to get to. Getting this 2nd row is screwing up the SUM functions I'm ultimately trying to use.
    SELECT
    SOE.SALESMAN_NO AS [SALESMAN],
    SOE.CUSTOMER_NO AS [CUSTOMER #],
    (SOE.SALE_ORDER_NO) AS [ORDERS],
    (SOE.SALES_AMT/100) AS [SALES],
    (SOE.COST_GOODS_SOLD/100) AS [COGS],
    ((SOE.SALES_AMT/100) - (SOE.COST_GOODS_SOLD/100)) AS [MARGIN]
    FROM
    SOE_HEADER SOE
    INNER JOIN CUST_NAME CUST
    ON SOE.CUSTOMER_NO = CUST.CUSTOMER_NO
    INNER JOIN OUTSIDE_SALES OUTSIDE
    ON CUST.SALESMAN_NO = OUTSIDE.SALESMAN_NO
    WHERE
    SOE.SALESMAN_NO <> '83'
    AND SOE.TYPE_OF_ORDER = '00'
    AND SOE.ORDERS_STATUS = '06'
    AND SOE.DATE_OF_ORDER > 20080101
    AND SOE.TYPE_OF_FRGHT IN ('13','14')
    AND SOE.CUSTOMER_NO = '1306969000'
    I've looked at the data and at this query for about an hour now, and need some help. Thanks.

    If you want to get the distinct rows only in this SELECT then you may use DISTINCT. ie replace the table with a query
    ,(Select Distinct SALESMAN_NO,CUSTOMER_NO, ORDER  SALES ,COGS , MARGIN From YourTableName) AS AliasName
    Check this too
    Find and/or Delete Duplicate Rows
    http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=DuplicateRows&referringTitle=Home
    Madhu
    SQL Server Blog
    SQL Server 2008 Blog

  • Crystal report returning duplicate rows - Linking issue?

    Hello,
    I know this is a commonly brought up issue - that duplicate rows are returned in Crystal reports for various reasons.  In a lot of instances, where it's only a single row of data per case that I'm looking for, I'll move them to their own group.  But that solution doesn't work here.
    The tables and links used in the simple report I have are illustrated in the attached "Report Database Expert Links.jpg" file, and the conditions and report fields required as as follows:
    Select Expert conditions:
    {CLAIM_PERIODS.CPE_START_DATE} < Today and
    {CLAIM_PERIODS.CPE_END_DATE} > Today and
    {CLAIM_ROLES.CRO_START_DATE} < Today and
    IsNull({CLAIM_ROLES.CRO_END_DATE})
    Report Design fields (in Details section):
    CLAIMS.CLA_REFNO, CLAIM_ROLES.CRT_CODE, PARTIES.PAR_PER_FORENAME, PARTIES.PAR_PER_SURNAME
    So what this report is to do:
    It looks for benefit claims which are live (have a CLAIM_PERIODS.CPE_START_DATE prior to today, and CLAIM_PERIODS.CPE_END_DATE after today), and for these claims gives a breakdown of all people in the household (everyone associated with that claim, where CLAIM_ROLES.START DATE is prior to today, and end date is null - to pick out those who are currently active in the household).
    This works fine otherwise, but the issue is that each live claim can have either one or two rows present in CLAIM_PARTS and CLAIM_PERIODS (so could satisfy my first two conditions twice).  For claims with only a single claim part active, I get each household member listed once.  But when they have two claim parts active, I get eveyone listed twice.
    Is there a way - either in how I'm linking the tables up, or how I'm arranging the report design, that I can have every household member only appear once no matter how many related rows there are in CLAIM_PARTS and CLAIM_PERIODS?
    Many thanks in advance,
    Sami
    P.S. I don't seem to be allowed to attache image files to my post, but have embedded the content instead:

    Thank you very much Don - this is a feature I wasn't aware of previously, and is a big step in the right direction for me.  Really useful.
    In the report mentioned, this sort of works.  It works very well on individual fields - so I could just "Suppress If Duplicated" on the forename and then remove duplicates on that column when exported to Excel (or simply bring in a unique field such as the party reference number and do likewise).
    However, is there a way to get Crystal to do this for me?  So to suppress the whole line based on whether or not I'm suppressing this one field?
    Just applying "Suppress If Duplicated" to all fields at once seems to have slightly unpredictable behaviour - not suppressing every field in the row.  So I experimented a bit with using the "Suppress" tick to do this, then applying a formula to it.  But the closest I can get for the formula is something like:
    -     {PARTIES.PAR_PER_FORENAME} = previous({PARTIES.PAR_PER_FORENAME}) and
    {PARTIES.PAR_PER_SURNAME} = previous({PARTIES.PAR_PER_SURNAME}) and
    Which will only compare the current row with previous.  Is there a way to do the same comparison but with all previous rows?

  • Report Builder 2.0 returning duplicate rows in query designer

    Hi,
    I have a query running off a model, when I explore the data in the model and in a standard sql table it returns one row for each record, which include a unique id for each which is correct.
    When I go into report builder query designer, it shows duplicate rows for each record. I have removed and added fields to try and pin point why and the only reason i can come up with is that it runs fine until I add in a field thats varchar(255) or
    varchar(max). This is when it starts to duplicate the records.
    Can anyone tell me why it does this or point me in the direction of how to stop this. I can't edit the query in text to add DISTINCT so thats not an option.
    Many thanks,
    JJSJ

    OK - I have found a partial answer.   By Googling Report Builder and VARCHAR, I found another post which reported problems with the semantic query builder when the underlying table/view was returning columns of type VARCHAR(MAX).   
    On looking at the length setting for the data column in the DSV,  this reported a length of 2,147,483,647 for this field.   This is very odd because on querying the underlying table the largest length that I can find for this column is 191,086
    (which is far larger than I would have expected - I am investigating this separately).
    However, why should the Report Model think that this field contains such a large value?
    Anyway,  the other post that I found reported that they had solved their problem by converting the field to a VARCHAR (255).    I tried this (by casting the column in my View to VARCHAR(255))  and this resolved the problem
    - no more duplicate rows when adding this field to the query!!!
    I also tried CASTING to TEXT and to VARCHAR(8000).  The former did not resolve the problem; the latter did.
    So I have a workaround but I don't understand why.  
    Can anybody explain why having a VARCHAR(max) column in my entity causes duplicate rows.    
    I suspect it is to do with the fact that for some reason the Report Model seems to think that there is an exceptionally long text string stored in this column in one of the rows but that again is a puzzle.
    Thanks
    Richard

  • Returning duplicate rows only

    Hi All,
    I need a Query to get only duplicate rows from a table. It should print the duplicate rows the number of times .
    it exists in the table.

    Added some duplicate records in emp table
    select count(*),empno,ename,job,mgr,hiredate,deptno from emp group by empno,ename,job,mgr,hiredate,deptno
      COUNT(*)  EMPNO ENAME      JOB              MGR HIREDATE      DEPTNO
         2       7782 CLARK      MANAGER         7839 09-JUN-81         10
         5       7844 TURNER     SALESMAN        7698 08-SEP-81         30
         3       7698 BLAKE      MANAGER         7839 01-MAY-81         30
         1       7900 JAMES      CLERK           7698 03-DEC-81         30
         1       7654 MARTIN     SALESMAN        7698 28-SEP-81         30
         1       7788 SCOTT      ANALYST         7566 19-APR-87         20
         1       7566 JONES      MANAGER         7839 02-APR-81         20
         6       7521 WARD       SALESMAN        7698 22-FEB-81         30
         5       7369 SMITH      CLERK           7902 17-DEC-80         20
         4       7934 MILLER     CLERK           7782 23-JAN-82         10
         1       7499 ALLEN      SALESMAN        7698 20-FEB-81         30Count(*)>1 are having duplicates
    Filter this with condition Count(*)>1
    select count(*),empno,ename,job,mgr,hiredate,deptno from emp group by empno,ename,job,mgr,hiredate,deptno having count(*)>1
      COUNT(*)  EMPNO ENAME      JOB              MGR HIREDATE      DEPTNO
         2       7782 CLARK      MANAGER         7839 09-JUN-81         10
         5       7844 TURNER     SALESMAN        7698 08-SEP-81         30
         3       7698 BLAKE      MANAGER         7839 01-MAY-81         30
         6       7521 WARD       SALESMAN        7698 22-FEB-81         30
         5       7369 SMITH      CLERK           7902 17-DEC-80         20
         4       7934 MILLER     CLERK           7782 23-JAN-82         10Edited by: Lokanath Giri on २४ जनवरी, २०१२ १०:४६ पूर्वाह्न

  • DB / Integation adapter returning duplicate rows on select [not all rows]

    I am seeing some unusal behavior, we have Application adapter invoking BEPL and which invokes DB adapter to make a select call to ERP database. Select should return 2 different records, where as in the response xml it has same record [only first record] listed twice. On DB adapter wsdl, -"Return Single Resultset " is unchecked. Should this be checked? or is there any other reason why the first record may be cached. I have not seen this in other connectors, restarted server but still same issue. connector is in prod environment. Any help/ideas are welcome.
    Edited by: user3622460 on Aug 5, 2009 10:23 PM

    Can you tell us more about the options you have selected in the Adapter to select the records ?

  • Advanced Table Duplicate Rows

    I have an advancedTable (master-detail). In one instance the "advancedTable" object suppresses duplicate master records, but in another instance, duplicate rows are not suppressed. If I run the VO query associated with the advancedTable object, the query returns duplicate rows in both instances. Has anyone seen this before? I have also run the pages from JDev connecting to each instance and the same result is exhibited.
    Thanks,
    LC

    -- application release 11.5.10.2 (both environments)
    -- database version 10.2.0.3 (stage) and 11.1.0.7 (dev)
    -- OS - RHEL 5 (both evironments)
    Both instances are not identical. The stage environment is RAC vs. dev which is not RAC.
    Steps to reproduce:
    Create an advancedTable in an advancedTable in JDev using a viewLink to establish the master-detail relationship. Run the page either from JDev connecting to each dev and stage environment directly. In addition to running local, I have also migrated all source to both the dev and stage instance. Run the page - in the dev instance, the results table displays only a subset of the rows (duplicate rows are removed - ie instead of 12 rows which is what the query returns both from executing the select statement in SQLPlus and by SOP vo.getRowCount() only 6 rows are displayed in the master table). However, when the same page is executed using the stage environment, all applicable rows are displayed - duplicates are not removed. This happens both from running the page locally and from logging into each respective application server.
    Thanks,
    LC

  • How just return one row of a one to many join..

    So I have a one to many join where the SMOPERATOR table has data I need however it has a couple of rows that match the JOIN condition in there. I just need to return one row. I think this can be accomplished with a subquery in the join however have not been able to come up with the right syntax to do so.
    So:
    SELECT "NUMBER" as danumber,
    NAME,
    SMINCREQ.ASSIGNMENT,
    SMOPERATOR.PRIMARY_ASSIGNMENT_GROUP,
    SMOPERATOR.WDMANAGERNAME,
    SMINCREQ.owner_manager_name,
    SMINCREQ.subcategory, TO_DATE('01-'||TO_CHAR(open_time,'MM-YYYY'),'DD-MM-YYYY')MONTHSORT,
    (CASE WHEN bc_request='f' THEN 'IAIO'
    WHEN (bc_request='t' and substr(assignment,1,3)<>'MTS') THEN 'RARO'
    WHEN (bc_request='t' and substr(assignment,1,3)='MTS') THEN 'M'
    ELSE 'U' end) as type
    from SMINCREQ
    left outer join SMOPERATOR on SMINCREQ.assignment=SMOPERATOR.primary_assignment_group
    WHERE SMINCREQ.owner_manager_name=:P170_SELECTION and SMOPERATOR.wdmanagername=:P170_SELECTION
    AND open_time BETWEEN to_date(:P170_SDATEB,'DD-MON-YYYY') AND to_date(:P170_EDATEB,'DD-MON-YYYY')
    AND
    (bc_request='f' and subcategory='ACTIVATION' and related_record<>'t')
    OR
    (bc_request='f' and subcategory<>'ACTIVATION')
    OR
    (bc_request='t' and substr(assignment,1,3)<>'MTS')
    order by OPEN_TIMe

    Hi,
    This sounds like a Top-N Query , where you pick N items (N=1 in this case) off the top of an orderded list. I think you want a separate ordered list for each assignment; the analytic ROW_NUMBER function does that easily.
    Since you didn't post CREATE TABLE and INSERT statements for your sample data, I'll use tables from the scott schema to show how this is done.
    Say you have a query like this:
    SELECT       d.dname
    ,       e.empno, e.ename, e.job, e.sal
    FROM       scott.dept  d
    JOIN       scott.emp   e  ON   d.deptno = e.deptno
    ORDER BY  dname
    ;which produces this output:
    DNAME               EMPNO ENAME      JOB              SAL
    ACCOUNTING           7934 MILLER     CLERK           1300
    ACCOUNTING           7839 KING       PRESIDENT       5000
    ACCOUNTING           7782 CLARK      MANAGER         2450
    RESEARCH             7876 ADAMS      CLERK           1100
    RESEARCH             7902 FORD       ANALYST         3000
    RESEARCH             7566 JONES      MANAGER         2975
    RESEARCH             7369 SMITH      CLERK            800
    RESEARCH             7788 SCOTT      ANALYST         3000
    SALES                7521 WARD       SALESMAN        1250
    SALES                7844 TURNER     SALESMAN        1500
    SALES                7499 ALLEN      SALESMAN        1600
    SALES                7900 JAMES      CLERK            950
    SALES                7698 BLAKE      MANAGER         2850
    SALES                7654 MARTIN     SALESMAN        1250Now say you want to change the query so that it only returns one row per department, like this:
    DNAME               EMPNO ENAME      JOB              SAL
    ACCOUNTING           7782 CLARK      MANAGER         2450
    RESEARCH             7876 ADAMS      CLERK           1100
    SALES                7499 ALLEN      SALESMAN        1600where the empno, ename, job and sal columns on each row of output are all taken from the same row of scott.emp, though it doesn't really matter which row that is.
    One way to do it is to use the analytic ROW_NUMBER function to assign a sequence of unique numbers (1, 2, 3, ...) to all the rows in each department. Since each sequence startw with 1, and the numbers are unique within a department, there will be exactly one row per departement that was assigned the numebr 1, and we''ll display that row.
    Here's how to code that:
    WITH     got_r_num     AS
         SELECT     d.dname
         ,     e.empno, e.ename, e.job, e.sal
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.dname
                                   ORDER BY          e.ename
                           )         AS r_num
         FROM     scott.dept  d
         JOIN     scott.emp   e  ON   d.deptno = e.deptno
    SELECT       dname
    ,       empno, ename, job, sal
    FROM       got_r_num
    WHERE       r_num     = 1
    ORDER BY  dname
    ;Notice that he sub-query got_r_num is almost the same as the original query; only it has one additional column, r_num, in the SELECT clause, and the sub-qeury does not have an ORDER BY clause. (Sub-queries almost never have an ORDER BY clause.)
    The ROW_NUMBER function must have an ORDER BY clause. In this example, I used "ORDER BY ename", meaning that, within each department, the row with the first ename (in sort order) will get r_num=1. You can use any column, or expression, or expressions in the ORDER BY clause. You muight as well use something consistent and predictable, like ename, but if you really wanted arbitrary numbering you could use a constant in the analytic ORDER BY clause, e.g. "ORDER BY NULL".

  • Simple join question - my query is returning unwanted rows ...

    My SQL select is returning more rows that I want it to return. The table that I'm joining on has multiple rows per CaseId, and I'm only interested in getting one...
    table1
    CaseId     column1     column2
    8     elmo          foz
    9     foo          bar
    10     fuz          baz
    11     fuy          bay
    table2
    CaseId     Seq     column8     column9
    8     1     choc          strawberry
    9     1     banana          orange
    9     2     do          re
    10     1     me          fa
    So a SQL select like:
    select t1.CaseId, t1.column1, t1.column2, t2.column8
    FROM table1 t1 LEFT OUTER JOIN table2 t2
    ON t1.CaseId = t2.CaseId
    returns data like:
    t1.CaseId     t1.column1     t1.column2     t2.column8
    8          elmo          foz          choc
    9          foo          bar          banana
    9          fuz          baz          do
    I want the SQL select to return only one row for each row that’s in table1; CaseId of 9 should have only one row in the SQL select results.
    The table2 has multiple rows, because of the Seq column. How can I formulate the SQL select to join on table2 using CaseId and the max Seq value?
    Thank you!

    Untested..
    with t1 AS
            (SELECT *
               FROM (SELECT table2.*,
                            ROW_NUMBER ()
                               OVER (PARTITION BY caseid ORDER BY seq DESC)
                               r
                       FROM table2)
              WHERE r = 1)
    SELECT t1.CaseId,
           t1.column1,
           t1.column2,
           t2.column8
      FROM table1 t1 LEFT OUTER JOIN t1 t2 ON t1.CaseId = t2.CaseId;OUTPUT:
    CASEID     COLUMN1     COLUMN2     COLUMN8
    8     elmo     foz     choc
    9     foo     bar     do
    10     fuz     baz     me
    11     fuy     bay     Cheers,
    Manik.

  • Remove Duplicate Rows from Left Outer Join

    Hi All,
    I am new to Oracle..I have two tables as follow:
    TableA(EmpID, Empname)
    TableB(EmpID, DeptID, DeptName). A employee can work in multiple dept.
    table A has 1 row as EmpID 1 and TableB has two rows for EmpID 1.
    I have a search page which takes dept ID as parameter and return employee name...Dept ID is not mandatory feld for Search. If DeptID is passed it should return the employee who belongs to that Dept otherwise it should return 1 employee..
    Now I have used as follow:
    :IN_DEPTID is passed as parameter
    Select EmpName from TableA Left Join tableB on a.EmpID = B.EmpID
    WHERE
    CASE WHEN :IN_DEPTID IS NULL
    IN_DEPTID IS NULL
    ELSE|
    DEPTID = :IN_DEPTID
    Now problem is when Dept ID is passed it correctly returns a row but if no deptid is passed it returns 2 rows but i want ony one row as there is only one employee.
    Please help;
    Edited by: user10239708 on 10 Sep, 2008 12:24 AM
    Edited by: user10239708 on 10 Sep, 2008 12:28 AM

    Try this
    Select
    from
         tableA a
    where
         (exists (select 1 from tableB b where a.empid = b.empid and deptid = :IN_DEPTID )
         or
         :IN_DEPTID is null) you database design is not good you should keep the emp, department mapping in different table.
    Regards
    Singh

  • Duplicate rows returned by contex index

    Hi
    I have a context index - locally partitioned with concatenated datastore.
    When I run a query on this it gives me duplicate rows (But for some rare cases only).
    Is this a bug in Oracle text?
    The table is partitioned on column norm_state_query - This query gives a duplicate -
    select rowid
    from mv_borrower_branch_details
    where contains ( norm_state_query, '( ( (fuzzy(${TATA},60,20,n) OR fuzzy(${PGIMENTS},60,20,n) OR fuzzy(${TATAPGIMENTS},60,20,n)) within norm_concat_name ) ) and ( ( ({43} OR fuzzy(${CHOWRINGHEE},60,20,n) ) within norm_concat_address ) )', 1 ) > 0
    and norm_state_query = 'WEST BENGAL'
    AAAKOGAAPAAAETMAAQ
    AAAKOGAAPAAAETMAAQ
    Thanks and regards
    Pratap

    Have you changed the partition definitions since you first created the index?
    Maybe that could cause the problem.
    Otherwise, it does sound like a bug. Please contact support so they can work
    through it with you.

  • Order by results in duplicates rows returned

    Hi All,
    Just got the following question that I could not understand at all. Let's assume we have a query like this:
    select d.d_name, e.e_name
    from dept d, emp e
    where d.d_id = e.d_id
    And this query returns 3 rows only:
    IT JOHN
    IT JAMES
    ADMIN BILL
    It was found that if the query was changed as:
    select d.d_name, e.e_name
    from dept d, emp e
    where d.d_id = e.d_id
    ORDER BY d.d_name, d.e_name
    sometimes it returns as 4 rows instead of 3:
    ADMIN BILL
    IT JAMES
    IT JAMES
    IT JOHN
    How this be possible?
    This happened sometimes on windows platform.

    Hi All,
    Just got the following question that I could not understand at all. Let's assume we have a query like this:
    select d.d_name, e.e_name
    from dept d, emp e
    where d.d_id = e.d_id
    And this query returns 3 rows only:
    IT JOHN
    IT JAMES
    ADMIN BILL
    It was found that if the query was changed as:
    select d.d_name, e.e_name
    from dept d, emp e
    where d.d_id = e.d_id
    ORDER BY d.d_name, d.e_name
    sometimes it returns as 4 rows instead of 3:
    ADMIN BILL
    IT JAMES
    IT JAMES
    IT JOHN
    How this be possible?
    This happened sometimes on windows platform.

  • DBA_CONSTRAINTS - self join - duplicate rows?

    Hi,
    I have two tables in 'I' schema.
    ===========
    SQL> desc dept;
    Name Null? Type
    DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14)
    LOC VARCHAR2(13)
    DEPT.DEPTNO - pk_dept_deptno - PRIMARY KEY
    SQL> desc emp;
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    EMP.DEPTNO - fk_emp_deptno - FORIGN KEY (DEPT. DEPTNO)
    SQL> desc emp2
    Name Null? Type
    DEPTNO NUMBER
    FUNCTION VARCHAR2(10)
    EMP2 . DEPTNO - fk_emp2_deptno - FORIGN KEY (DEPT. DEPTNO)
    I executed the query as DBA,
    SQL>
    select p.constraint_name,p.table_name,p.r_constraint_name,r.constraint_name,r.table_name
    from dba_constraints p, dba_constraints r
    where p.r_constraint_name=r.constraint_name and p.owner='I'
    order by p.constraint_name;
    CONSTRAINT_NAME | TABLE_NAME | R_CONSTRAINT_NAME | CONSTRAINT_NAME | TABLE_NAME
    FK_EMP2_DEPTNO | EMP2 | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
    FK_EMP2_DEPTNO | EMP2 | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
    FK_EMP_DEPTNO | EMP | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
    FK_EMP_DEPTNO | EMP | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO|
    DEPT
    Why I am getting duplicate rows? Any think wrong in my query?
    regards
    Mathew

    Hi,
    You can query on USER_CONSTRAINTS instead of DBA_CONSTRAINTS.
    SQL> ed
    Wrote file afiedt.buf
      1  select p.constraint_name, p.table_name, p.r_constraint_name, r.constraint_n
    ame, r.table_name
      2  from user_constraints p , user_constraints r
      3* where p.r_constraint_name = r.constraint_name
      4  /
    SQL> /
    CONSTRAINT_NAME TABLE_NAME      R_CONSTRAINT_NA CONSTRAINT_NAME TABLE_NAME
    SYS_C005292     B               PK_NO           PK_NO           A
    FK_DEPTNO       EMP             PK_DEPT         PK_DEPT         DEPT
    SQL> ed
    Wrote file afiedt.buf
      1  select p.constraint_name, p.table_name, p.r_constraint_name, r.constraint_n
    ame, r.table_name
      2  from dba_constraints p , dba_constraints r
      3  where p.r_constraint_name = r.constraint_name
      4  and p.owner = 'SCOTT'
      5* order by p.constraint_name
    SQL> conn sys as sysdba
    Enter password:
    Connected.
    SQL> /
    CONSTRAINT_NAME TABLE_NAME      R_CONSTRAINT_NA CONSTRAINT_NAME TABLE_NAME
    FK_DEPTNO       EMP             PK_DEPT         PK_DEPT         DEPT
    SYS_C005292     B               PK_NO           PK_NO           A
    SYS_C005292     B               PK_NO           PK_NO           A
    SQL>Message was edited by:
    Mohammad Taj

  • Duplicate rows in 5 table

    I have five tables(A,B,C,D,E), and I am trying to check for duplicate rows in all the tables, I tried using inner join, but the first three join did not return any table. is there another way.the tables only have two columns , the email(different values)
    and authour (which is the same person in the table)
    when i tried 
    select * from TABLE A
    INNER JOIN TABLE B
    ON TABLEA. EMAIL = TABLEB.EMAIL
    INNER JOIN TABLEC
    ON TABLEA.EMAIL=TABLEC.EMAIL
    it came back with no result, the other way I am thinking is to unioun all all the tables and try to use count and group by ,but this will only show me the duplicates and not the authours
    please any other way

    it came back with no result, the other way I am thinking is to unioun all all the tables and try to use count and group by (but I could not insert my result in a new table)
    please any other way
    I dont understand your point here...Are you trying the below?
    Create Table T1(name varchar(50),Email Varchar(50))
    Insert into T1 Values('SQL','[email protected]'),('.NET','[email protected]')
    Create Table T2(name varchar(50),Email Varchar(50))
    Insert into T2 Values('Server','[email protected]'),('BizTalk','[email protected]')
    Create Table T3(name varchar(50),Email Varchar(50))
    Insert into T2 Values('Sql','[email protected]'),('server','[email protected]')
    ;With cte as
    (Select * From T1
    Union All
    Select * From T2
    Union All
    Select * From T3)
    Select name,email, count(1) From cte Group by name , email having count(1)>1
    Drop table T1,T2,T3
    I was able to insert the union product in a table, and i used this 
    SELECT EMAIL,AUTHOR,COUNT(EMAIL) AS AMOUNT FROM ALLEMAIL
     GROUP BY AUTHOR,EMAIL
     ORDER BY  AMOUNT DESC, email desc
    but its showing the email and the count but its appearing like the duplicate is only associated with one authour

  • Query to return ALL rows even those with zero counts

    Hi,
    The following query will return only those rows that have a non zero count value:
    select c.id, a.name, count(*) as XYZ from CON c, CUST a
    where c.help !='1' and (c.id = a.id) group by c.id, a.name order by c.id;
    The results are:
    1 ME 3
    3 YOU 4
    What i want is to return all rows in CUST and the count, XYZ, that correspond to each row in CUST that matches the whare condition above, even if the count is zero.
    ie
    1 ME 3
    2 WE 0
    3 YOU 4
    Can this be done?

    You may want to get the counts then do the outer join. If you simply count with an outer join you will get 1 for 'WE' because there is a row in the cust table with 'WE'. This may work for you;
    with
      cust as (
       select 1 id, 'ME' name from dual union all
       select 2 id, 'YOU' name from dual union all
       select 3 id, 'WE' name from dual),
      con as (
       select 1 id, '2' help from dual union all
       select 1 id, '2' help from dual union all
       select 1 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual)
    -- end of test data 
    select a.id, a.name, nvl(c.cnt,0) xyz
    from cust a, 
       (select id, help, count(*) cnt
       from con
       where help !='1'
       group by id, help) c
    where a.id = c.id(+)

Maybe you are looking for

  • Clientless VPN and Java not working correctly

    In a recent discovery we found that the newest version of java will not work with our Cisco SSLVPN setup We are using an ASA5510 with 8.0.4 IOS version and 6.1.3 ADSM version and most users use an mstsc.exe smart tunnel to rdp into our terminal serve

  • My new MacBook Pro shut down and won't turn on.

    I connected it to the charger and there is no light to indicate that it's charging . What do I do ? Should I be really worried ? I just got it about a month ago

  • Sorting in ArrayField widget.

    Hi, We are using ArrayField widget. Forte does not provide any in-built sorting facility in ArrayField as it does in ListView. Is there an easy way to do that? If we implement our own sorting algorithm then how do we make it generic method for differ

  • Episode not appearing

    Hi there, I have uploaded an episode and it has not appeared. It is in Soundcloud, on Stitcher, and appears in my RSS feed. http://feeds.soundcloud.com/users/soundcloud:users:102727605/sounds.rss I previously uploaded an the same episode, but had to

  • OpenSSH 4.3p1 Compile Issues (Bad OpenSSL Headers)

    I was upgrading the version of OpenSSH on my other systems and thought I would also upgrade it on my Mac. The distributed version was OpenSSH 3.8p1 IIRC. First I find that the version of Zlib is out of date. Not surprising and very excusable. So I fi