Join two tables using union
Hi Gurus,
I have three tables. I want to join all tables using union in SQL statement. The query is returning all the records from both tables but i only require unique rows based on a specific column value. Here is my table structure -
TableA -
LIC_ID NUMBER(10) NOT NULL
LIC_NUMBER VARCHAR2(20)
COMMENCE_DATE DATE
EXPIRY_DATE DATE
TERM VARCHAR2(20)LIC_ID is the primary key in this table -
Sample data from TableA
LIC_ID LIC_NUMBER COMMENCE_DATE EXPIRY_DATE TERM
2 TR4323 12/04/2008 11/03/2010 2 Years
34 TR5432 23/07/2009 22/07/2010 1 Year
45 TR5321 24/06/2009 23/06/2010 1 Year
65 TR6666 23/07/2010 22/07/2011 1 Year
32 TR2423 30/05/2010 29/05/2011 1 YearTableB -
MAR_ID NUMBER(10) NOT NULL
LIC_ID NUMBER(10) NOT NULL
ZONE_NAME VARCHAR2(20)
DEPARTMENT VARCHAR2(20)
ACTIVITIES VARCHAR2(200)
COMMENTS VARCHAR2(200)MAR_ID is the primary key in this table and LIC_ID is the foreign key on TableA
Sample data from TableB -
MAR_ID LIC_ID ZONE_NAME DEPARTMENT ACTIVITIES COMMENTS
23 2 ZONE A IT NONE
43 34 ZONE B IT NONE
33 65 ZONE C ACCOUNT NONE
TableC
REC_ID NUMBER(10) NOT NULL
LIC_ID NUMBER(10) NOT NULL
DIST_NAME VARCHAR2(20)
REGION VARCHAR2(20)
ACTIVITIES VARCHAR2(200)
COMMENTS VARCHAR2(200)REC_ID is the primary key in this table and LIC_ID is the foreign key.
Sample data -
REC_ID LIC_ID DIST_NAME REGION ACTIVITIES COMMENTS
2 45 SA NORTH NONE
3 65 TA NORTH NONE
5 32 NT SOUTH NONEHere is my sql query -
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableB b
where a.lic_id=b.lic_id
union
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableC c
where a.lic_id=c.lic_idThe above query returns -
lic_id lic_number commence_date expiry_date
2 TR4323 12/04/2008 11/03/2010
34 TR5432 23/07/2009 22/07/2010
45 TR5321 24/06/2009 23/06/2010
65 TR6666 23/07/2010 22/07/2011
32 TR2423 30/05/2010 29/05/2011
65 TR6666 23/07/2010 22/07/2011 LIC_ID 65 exists in both table TableB and TableC hence it repeats in query but I want to display that only once. How can I do that? I want to return unique record on LIC_NUMBER.
Hope this make sence.
Many thanks,
Tajuddin
Thanks for all your reply and suggestions. David altering session did not work.
Sven your idea helped me to figure it out what to do. I found a way around to fix it. Here is my current code -
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableB b
where a.lic_id=b.lic_id
union
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableC c
where a.lic_id=c.lic_id and c.lic_id not in ( select lic_id from TableB)This will exclude any LIC_ID exists in TableB.
Thanks again for your help guys.
Regards,
M Tajuddin
Web: http://tajuddin.whitepagesbd.com
Blog: http://aspblog.whitepagesbd.com
Similar Messages
-
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
Join two table using two link field
hi all
i need to left join two table, and to link two table need to match two field
ex: the link field is store_name and id
i use below sql statement
SELECT A1.store_name, A1.id, A1.card, A2.sale, A2.history
FROM Georgraphy A1, Store_Information A2
WHERE A1.store_name = A2.store_name(+)
AND A1.id = A2.id(+)
but it's wrong
please tell me how to left join A1 and A2, thx!Whats your aim?
Any error message?
SQL> select * from geography;
ID STORE_NAME
1 a
1 b
2 a
2 b
SQL> select * from store_information;
ID STORE_NAME
1 a
3 d
SQL> SELECT *
2 FROM Geography A1, Store_Information A2
3 WHERE A1.store_name = A2.store_name(+)
4 AND A1.id = A2.id(+);
ID STORE_NAME ID STORE_NAME
1 a 1 a
2 a
2 b
1 b -
Joining two tables using PL/SQL
here i am trying to join two tables can any one tell me what is wrong with this syntex
CREATE OR REPLACE PROCEDURE test IS
CURSOR c1 IS SELECT seq,fname,lname from t1;
CURSOR c2 IS SELECT seq1,q,a from t2;
userjob number;
BEGIN
OPEN c1;
insert into t3 values(c1.seq,c1.fname,c1.lname);
FETCH c1.seq INTO userjob;
FOR c1rec IN c2 LOOP
IF (c1rec.seq=c1.seq and c1rec.q1='why') THEN
insert into t3 values(c1rec.q1,c1rec.a1);
elsif (c1rec.seq=c1.seq and c1rec.q1='what') then
insert into t3 values(c1rec.q2,c1rec.a2);
elsif (c1rec.seq=c1.seq and c1rec.q1='when') then
insert into t3 values(c1rec.q3,c1rec.a3);
elsif (c1rec.seq=c1.seq and c1rec.q1='where') then
insert into t3 values(c1rec.q4,c1rec.a4);
END IF;
END LOOP;
END;
/You should always fetch a cursor before using it's values. All columns in the select should be fetched into variables or a record-variable. You can't refer to the cursor-columns values with c1.seq etc.
r1 c1%rowtype;
l_found boolean;
BEGIN
OPEN c1;
FETCH c1 INTO r1;
insert into t3 values(r1.seq,r1.fname,r1.lname);
l_found := c1%found;
close c1;
if l_found
then
It is also better to close the cursor and check if the select resulted in a row. With this code you will only retrieve one row even if the select will result in multiple rows.
But I agree with all the others that this can probably be done more efficiently with one SQL statement. -
How to Join two tables using the Inner Join
Hi All,
I have two tables i.e table1 and table2 as i have created two otds and my present requirement is to join this two tables and get the results and using this i need to do some logic and update another table3.
can some one help me out how to go for the above req.
Thanks in Advance
SrikanthThe best efficient way to use inner join is create two input otds,use there otd's in create a collaboration usinf etl.
after selecting two input otd's create a inner join statement and map it to out put otd.
while using the etl the performance of the over all integration is increased 20 time of the normal integration.
Hopes this will helps,,
Thanks,
Papa Rao. -
How to join two tables using EJB-QL
Hi There,
How to join tables using EJB-QL ?
Thanks.
Edited by: vamseebobby on Nov 6, 2007 8:12 AMYou might try
SELECT b.entity2property FROM Entity1 a JOIN a.entity2 b
for example, to retrieve players names, from a Players table, that belong to the team 'My Team' in the Teams table
SELECT b.playerName FROM Teams a JOIN a.players b WHERE a.teamName = 'My Team' -
How to join two tables using UD Connect ?
Hi,
I have 2 tables on which I need to create join & extract the data from Oracle database using UD connect. Is this possible? If yes, please let me know how or suggest an alternative approach.
Thanks,
SunilThanks Tony for the reply.. Actually, the issue is Netweaver Java dictionary doesn't allow you to create a view, right? Also, I dont want to create a view directly on the database.
I want to handle this on BI side somehow. -
Join two table (Inner Join)
how to join two tables using inner join.
Tariq,
Pretty vague question. You can create joins in an ABAP program, or while creating a view, or when creating a SAP query of one type or another. Some people download tables and then join them using desktop software. If you can elaborate your question I may be able to give you a better answer.
I recently joined two wooden tables at a picnic. I used 24 gauge galvanized wire combined with duct tape, so I guess you couldn't really call that an 'inner join'.
Best Regards,
DB49 -
hi
how to join two tables using inner join if the first table has two primary keys and second table has 3 primary keysWould describe type of joins in ABAP, which might differ with other joins.
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following additions not be used: NOT, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
Note
If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
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 = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP. -
Using a view to join two tables
Thank you in advance for any advice you can lend.
I am using this code in my MySQL db to create a view.
select
job.id as job_id,
umr_cost_calculation.plant_name,
max(umr_cost_calculation.id) as max_id
from
job,
umr_cost_calculation
where
job.id = umr_cost_calculation.job_id
group by job.id , umr_cost_calculation.plant_name
I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
2) If I leave the max_id on the report, will this force the view to always update?Try:
Select
D1.EmpLoginID,
Count(D1.ID),
Count(D1.AlarmCode),
D1.EmpName,
D1.EmpAddress,
D2.Db2Count
FROM DB1.Data D1
LEFT JOIN (SELECT
empLoginID, Count(*) as Db2Count
FROM DB2.ALL_Database
WHERE site = 'Atlanta'
GROUP BY empLoginID
) D2
ON D1.EmpLoginID = D2.EmpLoginID
GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
Order BY D1.empLoginID ASC
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How do you join two tables from different Oracle schemas using a subquery
I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
The query is as follows:
sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
+ "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
+ "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
+ "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
The format of the query is copied from a SQL programming manual.
I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
Edited by: user11338343 on Oct 19, 2009 6:55 AMI believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
If you want to do a straight join without a subquery you could do the following
SELECT DD_12809.PDTABLE_12_1.LINE_ID
, FAB.MAT_DESCRIPTION
FROM DD_12809.PDTABLE_12_1
JOIN RA_12809.PDTABLE_201 AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS HTH! -
How to prevent Oracle from using an index when joining two tables ...
How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
O.K. I think I have to explain what I mean:
When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
I have two tables: table A and table B.
Table A has 4.000.000 entries and table B has 700.000 entries.
I have a join of both tables with a numeric column as join criteria.
There is an index on this column in table A.
So I instead of
where (A.col = B.col)I want to use
where (A.col+0 = B.col)in order to prevent Oracle from using the index.
When I use the join in a select statement it works.
But when I use the join as inline view in an update statement I get the error ORA-01779.
When I remove the "+0" the update statement works. (The column col is unique in table B).
Any ideas why this happens?
Thank you very much in advance for any help.
Regards HartmutI think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
In SQL*Plus:
SET LINESIZE 130
EXPLAIN PLAN FOR <your statement>;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
Regards,
Randolf
Oracle related stuff:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Joining two tables having no common fields using one select query
Hi Experts,
How to join two tables which are NOT having any field in common using only one select query?
Your help will be appreciated.
Thank you.Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
Regards,
Raymond -
Joining Two Tables based on Conditions.
Hi All,
i would like to join two tables emp and dept with conditional join like
for example: select emp.column1...............
left outer join DEPT ON if Dept.column1='A" then emp.column1=dept.column1
else emp.column2=dept.column3
i know that bu using the UNION we can dothis, but i donot want to USE UNION.
please let me know if any workaround for this.
Thanks,
KalyanSQL> select * from etl
2 /
EMPNO ENAME JOB MGR SAL COMM DEPTNO AAA DEPT_NO
7566 JONES MANAGER 7839 2975 20 2 20
7654 MARTIN SALESMAN 7698 1250 1400 30 3 10
7698 BLAKE MANAGER 7839 2850 30 3 10
7782 CLARK MANAGER 7839 2450 10 1 20
7788 SCOTT ANALYST 7566 3000 20 2 20
7839 KING PRESIDENT 5000 10 1 20
7844 TURNER SALESMAN 7698 1500 30 3 10
7876 ADAMS CLERK 7788 1100 20 2 20
7900 JAMES CLERK 7698 950 30 3 10
7902 FORD ANALYST 7566 3000 20 2 20
7934 MILLER5 CLERK 7782 1300 10 1 20
7936 MILLER7 CLERK 7782 1300 10 1 20
12 rows selected.
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> ed
Wrote file afiedt.buf
1 select
2 e.empno,
3 e.ename,
4 e.deptno,
5 aaa,
6 e.dept_no,
7 d.deptno,
8 d.dname
9 from
10 etl e ,
11 dept d
12 where
13 (e.aaa =1 and e.deptno = d.deptno) or
14* (e.aaa =2 and e.dept_no =d.deptno)
SQL> /
EMPNO ENAME DEPTNO AAA DEPT_NO DEPTNO DNAME
7566 JONES 20 2 20 20 RESEARCH
7788 SCOTT 20 2 20 20 RESEARCH
7876 ADAMS 20 2 20 20 RESEARCH
7902 FORD 20 2 20 20 RESEARCH
7782 CLARK 10 1 20 10 ACCOUNTING
7839 KING 10 1 20 10 ACCOUNTING
7934 MILLER5 10 1 20 10 ACCOUNTING
7936 MILLER7 10 1 20 10 ACCOUNTING
8 rows selected.Regards
Singh -
LEFT OUTER JOIN multiple tables - using the 9i syntax
I've always written my queries using the (+) operator for outer joins. I want to start using the new ANSI standard available in 9i. I can do it when I'm joining two tables in a simple query, but how does it work when I am joining multiple tables?
Here is an example of some SQL that works with the (+) outer join syntax. How can I convert this to use the LEFT OUTER JOIN syntax?
SELECT *
FROM audit_entry aue,
audit_table aut,
audit_statement aus,
audit_row aur,
audit_row_pkey aup1,
audit_row_pkey aup2
WHERE aue.audit_entry_id = aus.audit_entry_id
AND aut.table_name = 'TEST_AUDITING'
AND aut.table_owner = 'CLA_JOURNAL'
AND aus.audit_table_id = aut.audit_table_id
AND aur.audit_statement_id (+) = aus.audit_statement_id
AND aup1.audit_row_id (+) = aur.audit_row_id
AND aup1.pk_column_name (+) = 'TEST_AUDTING_PK_1'
AND aup2.audit_row_id (+) = aur.audit_row_id
AND aup2.pk_column_name (+) = 'TEST_AUDITING_PK_2'
I can join audit_statement to audit_entry easy enough, but then I want to join audit_table to audit_statement, how do I do that, do I start nesting the join statements?
Thanks
RichardThanks for getting back so quickly, I have tried the suggested SQL with mixed results:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
I had to change the order slightly, between the first two JOINs but otherwise it executed OK. My problem is, it should only return 175 rows but its returning 30625 rows. If I comment out the second reference to audit_row_pkey I get the expected result:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
--RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
--AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
It looks the same condition is being used in each case but why do I suddenly get so many rows - its joining differently somehow. It must be to do with the order, do I need to bracket the query?
Thanks again
Richard
Maybe you are looking for
-
Hey guys, I've tried syncing my iPad Contacts with iTunes, but all I get is the old, outdated info. I also set it to sync with the iCloud, but - no change. I thought this was supposed to be easy!
-
Problems with the "Date Created" Metadata in Adobe Bridge
Hi everyone. I am currently working on an electronic photo library for our organization. Part of my mandate is to add a Date Created metadata on all the photos since it is very important to know when the photo was taken. Some photos were dated sinc
-
Why won't my Mac & Logic Pro detect my input device(s)?
Hey, I'm using a macbook with OSX 10.8.2 and Logic Pro with a steinberg interface. I have also tried a tascam interface that was given to me by a friend to try, but I still have the same problem: Logic doesnt detect either of the interfaces, and neit
-
FMS Audio (MP3) Glitches - Hosting Issue or Not
I've got several webinars that an associate of mine helped me build several years ago in Flash MX 2004. They are about 40 minutes long, but have been broken into about 8 chapters (seperate .swf files). The .swf files connect to audio (mp3) streams ru
-
I'm using Prores footage with metadata Timecode inserted into the Quicktime file. Then I edit the Quicktime file, click "Save" and then import the trimmed file into APP CS4. CS4 recognizes the edited clip and displays the timecode correctly (adhear