Join columns of outer join with table have no uniqueness cons
Hi! I'm getting noizy error in alert log from time to time:
Join columns of outer join with table <table_name> have no uniqueness constraints
I've collected all the queries (v$sql, all_source) with montioned table, but non of them produces that error if executed.
Any hints how to reproduce this error or where else to search that buggy sql join?
Edited by: user545083 on 25.10.2010 6:21
Hi
I think this error is output via an materialized view refresh - check for mviews against the given table which fulfil the issue given in the error text.
Thanks
Paul
Similar Messages
-
SQL Server Multiple JOINS with Table Value Function - query never ends
I have a query with 4 joins using a table value function to get the data and when I execute it the query never ends.
Issue Details
- Table value function
CREATE FUNCTION [dbo].[GetIndicator]
@indicator varchar(50),
@refDate datetime
RETURNS
TABLE
AS
RETURN
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
- Query
DECLARE @RefDate datetime
SET @RefDate = '30 April 2014 23:59:59'
SELECT DISTINCT OTHERTABLE.Id As Id
FROM
GetIndicator('ID#1_0#INDICATOR_X',@RefDate) AS OTHERTABLE
JOIN GetIndicator('ID#1_0#INDICATOR_Y',@RefDate) AS YTABLE
ON OTHERTABLE.SomeId=YTABLE.SomeId
AND OTHERTABLE.DateOfEntry=YTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_Z',@RefDate) AS ZTABLE
ON OTHERTABLE.SomeId=ZTABLE.SomeId
AND OTHERTABLE.DateOfEntry=ZTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_W',@RefDate) AS WTABLE
ON OTHERTABLE.SomeId=WTABLE.SomeId
AND OTHERTABLE.DateOfEntry=WTABLE.DateOfEntry
JOIN GetIndicator('ID#1_0#INDICATOR_A',@RefDate) AS ATABLE
ON OTHERTABLE.SomeId=ATABLE.SomeId
AND OTHERTABLE.DateOfEntry=ATABLE.DateOfEntry
Other details:
- SQL server version: 2008 R2
- If I execute the table function code outside the query, with the same args, the execution time is less the 1s.
- Each table function call return between 250 and 500 rows.Hi,
Calling function in general is a costly query. And definitely joining with a function 5 times in not an efficient one.
1. You can populate the results for all parameters in a CTE or table variable or temporary table and join (instead of funtion) for different parameters
2. Looks like you want fetch the IDs falling to different indicators for the same @Refdate. You can try something like this
WITH CTE
AS
SELECT
T1.Id ,T1.ColINT_1, T1.ColNVARCHAR_1 collate DATABASE_DEFAULT as ColNVARCHAR_1 ,T1.ColNVARCHAR_2 ,T1.ColSMALLDATETIME_1, T1.ColDECIMAL_1, T1.ColDECIMAL_1, T4.Name
FROM TABLE2 T2
JOIN TABLE3 T3
ON T2.COLFKT3 = T3.Id
AND T3.ReferenceDate = @RefDate
AND T3.State != 'Deleted'
JOIN TABLE4 T4
ON T2.COLFKT4 = T4.Id AND T4.Name=@indicator
JOIN TABLE1 T1
ON T2.COLFKT1=T1.Id
SELECT * FROM CTE WHERE Name = 'ID#1_0#INDICATOR_X' AND Name = 'ID#1_0#INDICATOR_Y' AND Name = 'ID#1_0#INDICATOR_Z' AND Name = 'ID#1_0#INDICATOR_W' AND Name = 'ID#1_0#INDICATOR_A' AND ReferenceDate = @RefDate.
Or you can even simplify more depends on your requirement.
Regards,
Brindha. -
Hello!
I am trying to create a query for material accounts with the Quick Viewer (transaction SQVI).
I´ve already added tables MARA, MBEW and T001K, but when i try to add table T030 an error message comes up:
"Table T030 cannot be used in a join" (Message #AQ 501)
Does Anyone know why the Quick Viewer doesn't let me add this table to the join of tables?
Thank you everybody in advance!
cecilDear Maria,
Not every table can be join using SQVI, eg:T030,A017,etc.
You can read the notes for this :
1. You cannot read the selected table with SELECT statements (because,
for example, it is a structure without a database table). Therefore,
this table cannot be read within a table join either.
2. The chosen table is a pool or cluster table. These tables may not be
used in a table join.
Regards, -
Issues while joining two tables as the joining column has duplicate values - Please help!
Hi,
I have a table A -which has few columns including a Amount column - I am joining this table A to Table B. The joining column in B has duplicates. So, the number of records are getting more after the joining. As per the requirment when I create a table
after joining the tables and count the salary clumn, there is a difference in the counting. How can I solve this? Can you please help me?
Here is the DDL and sample values
create table #student (sid int, name varchar(10),salary int)
create table [#address] (sid int, city varchar(10),grade char(1),lineneumber int)
insert into #student values (1,'sachin',8000)
insert into #student values (2,'Dhoni',2000)
insert into #student values (3,'Ganguly',7000)
insert into #student values (4,'Kohli',1000)
insert into [#address] values(1,'mumbai','A',1)
insert into [#address] values(1,'mumbai','B',2)
insert into [#address] values(1,'mumbai','C',3)
insert into [#address] values(1,'mumbai','D',4)
insert into [#address] values(2,'JARKHAND','D',3)
insert into [#address] values(2,'JARKHAND','D',4)
SELECT S.SID,NAME,salary,CITY ,grade,linenumber
into #FINAL
FROM #STUDENT S
LEFT JOIN #ADDRESS A
ON S.SID=A.SID
SELECT SUM(salary) FROM #FINAL
--44000
Final result should be 18000 , but it is coming as 44000. can you please help me to get the correct result - what do i do in the joining?
In my real project, i have 5 tables joining, each table have more than 30 columns and few joining tables joining column have duplicates. I have simplified the issue so that i can ask the question clearly. So,while answering, please consider that also in mind.
thanks in advance for your help!SELECT S.SID,NAME,salary,CITY
into #FINAL
FROM #STUDENT S
LEFT JOIN (SELECT DISTINCT sid,city
FROM #Address) A
ON S.SID=A.SIDthis will do a join on student table and city table with unique sid and city name so adddress selection will be sid city1 mumbai2 jarkand -
Problem with outer join with filter on join column
Hi,
In physical layer I have one dimension and two facts, and there's an outer join between the facts.
dim_DATE ,
fact_1 ,
fact_2
Joins:
dim_DATE inner join fact_1 on dim_DATE.DATE = fact_1.DATE
fact_1 left outer join fact_2 on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
When I run a report with a date as a filter, OBIEE executes "optimized" physical SQL:
select fact1.X, fact2.Y
from
Fact_1 left outer join on fact_1.DATE = fact_2.DATE and fact_1.SOME_ID = fact_2.SOME_ID
where Fact_1.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD' )
and Fact_2.DATE = TO_DATE('2009-05-28' , 'YYYY-MM-DD')
The filter on Fact_2.DATE effectively replaces outer join with inner.
Is there a way to disable this "optimization", which is actually very good for inner joins, but doesn't allow outer joins?
Thanks in advance,
Alex
Edited by: AM_1 on Aug 11, 2009 8:20 AMIf you want to perform a Fact-based partitioning with OBIEE (two fact with the same dimension), you have to :
* create in your physical layer for each fact table the joins with the dimension
* create in the Business Model layer ONE star schema with ONE logical fact table containing the columns of your two physical fact table
In this way when you choose minimal one column of your fact1 and one column of your fact2, OBIEE will perform two query against each fact table/dimension, join them with an OUTER JOIN and your problem will disappear.
Cheers
Nico -
Outer join with tow columns foreign key
If I want to select from two tables (A and B) with outer join on table "B" and I have two columns foregn key between the two tables what is the correct way:
1)
...from A,B
where A.key1 = B.key1 (+)
and A.key2 = B.key2 (+)
2)
...from A,B
where A.key1||A.key2 = B.key1||B.key2 (+)
thank you,
ENdre#1
-
Case statement resulting into Left outer join with other tables
Hi All ,
I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
If we remove the case stmt, the table is not being acessed.
The case stmt is a simple one and no other logical column is being accessed in the case stmt.
Please advice .
Thanks.Hi Sai,
No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
Thanks. -
Left outer join 3 tables with where-statement
Hi folks,
I hope you can understand (and maybe solve) my problem.
Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
The three table structures are the following:
table 1 (user)
user1 | key
table 2 (detail)
key | ID
table 3 (header)
ID | user2
...and I want to achieve the following structure (as example filled with data):
user | key | ID
|-----|----
xy | a | 001
xy | b | #
z | b | #
The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
I tried this coding:
SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
LEFT OUTER JOIN table2 AS b ON akey = bkey )
LEFT OUTER JOIN table3 AS c ON bID = cID )
WHERE auser1 = cuser2.
I would really appreciate your help.
Regards
MrclSpdlIF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
select dbfields
into table itab2
from dbtab
for all entries in itab
where dbfield1 = itab-field1.
This will get you a second internal table with all the corresponding data for the first selection. You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation). Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
Regards,
Freek -
JOIN 2 tables that have same column ?
I need to learn how to join two tables that both have the same column name:
tbl1 - idskey
tbl2 - idskey
the idskey column holds a id_number
When I do the JOIN I would like to make sure that only Distinct records are joined from both tables and that any duplicates are removed in the final join. So if:
Tbl1 has a idskey of: 12345
and
Tbl2 has a idskey of: 12345
In the final JOIN I want to remove one of those duplicates.
I actually need to join 3 tables that have the same linking column names for the join, but if I learn how to do this correctly on 2, that will be a start.
10g for db, thanks!Hi,
SELECT DISTINCT and GROUP BY are the most common ways to get unique results from non-unique keys. Exactly how you use them depends on exactly what you want to do.
SELECT DISTINCT guarantees that no two rows in the result set, conisdering all columns, will be identical.
GROUP BY produces one row from a set of rows that have a common feature. The values on that row may be a composite of values from various rows in that set (e.g., an average).
Please post a small, specific example. For instance:
"I have two rows in tbl1 ...
and these fhtee rows in tbl2 ...
Notice how there is one row with idskey=12345 in tbl1 but two such rows in tbl2.
How can I get theses results ...
where only one row has idskey=12345?" -
Outer join two tables with query search record attached to both tables
When I create a query with two tables that have query search records attached with outer join, PS seems to do a natural join (cartesian). We are on PT8.48.
Is there a workaround for this issue. I do not want to remove query search record on either of the tables.
I am trying to create an Emergency contact report. I am using two tables PS_EMPLOYEES and PS_EMERGENCY_CNTCT. Here is the sql PeopleSoft query generated when I did Left outer Join.
Query SQL:
SELECT A.EMPLID, A.NAME, A.ADDRESS1, A.CITY, B.PRIMARY_CONTACT, B.ADDRESS1, B.CITY, B.STATE, B.POSTAL, B.RELATIONSHIP, A.DEPTID, A.JOBCODE, A.COMPANY, A.EMPL_TYPE
FROM (PS_EMPLOYEES A LEFT OUTER JOIN PS_EMERGENCY_CNTCT B ON A.EMPLID = B.EMPLID ), PS_EMPLMT_SRCH_QRY A1, PS_PERS_SRCH_QRY B1
WHERE A.EMPLID = A1.EMPLID
AND A.EMPL_RCD = A1.EMPL_RCD
AND A1.OPRID = 'SREESR'
AND (B.EMPLID = B1.EMPLID OR B.EMPLID IS NULL )
AND B1.OPRID = 'PS'
Appreciate any help.I think there are fixes for this issue in later tools releases (Report ID 1544345000). I'm not sure about 8.48, but you might try the workaround documented in
E-QR: Left Outer Joins with Security Records are returning unexpected results [ID 651252.1]
on Oracle Support.
Regards,
Bob -
Maximum number of tables that can be outer joined with one table in a query
Hi All,
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
Thanks,
Srinisrinu2 wrote:
Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
There is no limit to the number of tables you can outer join as long as you join them correctly.
SQL> with a as
2 (
3 select 1 id, 2 b_key, 3 c_key from dual union all
4 select 2 id, 1 b_key, 4 c_key from dual union all
5 select 3 id, 3 b_key, 1 c_key from dual union all
6 select 4 id, 4 b_key, 2 c_key from dual
7 ),
8 b as
9 (
10 select 1 id, 1 c_key2 from dual union all
11 select 2 id, 5 c_key2 from dual union all
12 select 3 id, 3 c_key2 from dual union all
13 select 4 id, 2 c_key2 from dual
14 ),
15 c as
16 (
17 select 1 key1, 1 key2, '1-1' dta from dual union all
18 select 1 key1, 2 key2, '1-2' dta from dual union all
19 select 1 key1, 3 key2, '1-3' dta from dual union all
20 select 1 key1, 4 key2, '1-4' dta from dual union all
21 select 2 key1, 1 key2, '2-1' dta from dual union all
22 select 2 key1, 2 key2, '2-2' dta from dual union all
23 select 2 key1, 3 key2, '2-3' dta from dual union all
24 select 2 key1, 4 key2, '2-4' dta from dual union all
25 select 3 key1, 1 key2, '3-1' dta from dual union all
26 select 3 key1, 2 key2, '3-2' dta from dual union all
27 select 3 key1, 3 key2, '3-3' dta from dual union all
28 select 3 key1, 4 key2, '3-4' dta from dual union all
29 select 4 key1, 1 key2, '4-1' dta from dual union all
30 select 4 key1, 2 key2, '4-2' dta from dual union all
31 select 4 key1, 3 key2, '4-3' dta from dual union all
32 select 4 key1, 4 key2, '4-4' dta from dual
33 )
34 select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
35 from
36 c,
37 (
38 select
39 a.id as a_id, b.id as b_id, a.c_key, b.c_key2
40 from a, b
41 where a.b_key = b.id
42 ) d
43 where d.c_key = c.key1 (+)
44 and d.c_key2 = c.key2 (+);
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
Can we join 3 tables with left outer join
hi friends.
Can any one tell how to join 3 tables using <b>left outer join</b>...i tried by taking some fields of <b>ekko,ekpo,eket</b>, but this not working ... plz give a sample code with some fields.Hi Uday
<b>Inner joins using 3 tables </b>
<i><b>Try this :-</b></i>
SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpo~stlnr = mast~stlnr
JOIN mara ON mara~matnr = mast~matnr
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr
AND mast~werks = 1000.
<b><i>Here s_matnr is a select-options on the selection-screen. </i></b>
<i><b>Or this. </b></i>
<b>Code: </b>
Select single Vbrk~Bukrs Vbrk~Kunrg Vbrk~Vbeln
Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
Vbak~Vbeln Vbak~Bstdk
Likp~Vbeln Likp~lfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on Tvzbt~Zterm = Vbrk~Zterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on Vbak~Vbeln = SalesLnk~Vbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on Likp~Vbeln = DeliveryLnk~Vbelv
where vbrk~vbeln = pu_Vbeln.
<i><b>This code locates sales, delivery and payment terms info from a billing document number.</b></i>
<i><b>or</b></i>
<b>
Here, this one also works fine :</b>
select zfpcd~cadivi zfpcd~proforma zfpcd~factura zfpcd~aniofactura
zfpcd~montousd zfpcd~montoap zfpcd~ebeln zfpcd~inco1
zfpcd~lifnr lfa1~name1 zcdvs~status zfpcd~conint
into it_lista
from zfpcd inner join zcdvs
on zfpcd~ebeln = zcdvs~ebeln
and zfpcd~proforma = zcdvs~proforma
and zfpcd~lifnr = zcdvs~lifnr
inner join lfa1
on zfpcd~lifnr = lfa1~lifnr
where zcdvs~status = '04'.
Reward if helpfull
Regards
Pavan -
How can I crate a view with tables which require "Left outer join"?
Hi guys,
how can I define a view with tables which require "Left outer join"?. In SE11 "View",->tab "Join condition", it seems that it valid only for "Inner Join".
Please give me some hint.
Thanks in advance.
Regards,
LiyingHi
Inner Join and Outer Join
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join.
With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view.
With an outer join, records are also selected for which there is no entry in some of the tables used in the view. (ABAP allows left outer join.)
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. -
Joining Two Tables with Total Amount
Hi All,
I'm trying to join to tables P02 and P30 on the invoice no fields but getting duplicates. In table P30 we need to sum the payment column per invoice to get the actual payment amount. This then needs to Join to table P02. I have uploaded sample
data on this link and provided an example on how the output should like.
https://app.box.com/s/pu8oa4f3jhrhm0ylshdz2fuo7541vn4z
Thanks
JagI figured out why the duplicates appear. I'm attaching another table supplier to fill in the missing propcode when running the query below
SELECT P02.P02_UNIQUE, p30.PROP_CODE, P02.SUPP_ALPHA+P02.SUPP_NUMERIC As SupplierCode, P02.INV_ALPHA+P02.INV_NUMERIC AS InvoiceNo,TotalPayment, Year, Month
FROM P02
CROSS APPLY (
SELECT PROP_CODE, SUM(TOTAL_AMOUNT) AS TotalPayment, P30.INVOICE_NUMB, DATEPART(year,[CREATED_DATE_SQL]) AS [Year], DATEName(Month,[CREATED_DATE_SQL]) AS [Month]
FROM dbo.P30
WHERE P02.INV_ALPHA+P02.INV_NUMERIC = P30.INVOICE_NUMB
GROUP BY PROP_CODE, COST_CENTRE, DATEPART(year,[CREATED_DATE_SQL]), DATEName(Month,[CREATED_DATE_SQL]), P30.INVOICE_NUMB
)P30
Where P02.SUPP_ALPHA+P02.SUPP_NUMERIC = '668'
Result below and the last row the prop_code is missing
I have another table supplier which has the suppliercode and propcode so was trying to use the prop_code field from supplier table instead of P30 table to fill in the gap. But when i do that i get duplicates and wrong values.
I have updated the sample data with supplier table. -
Outer join With a constant value
Hi all,
In one of query i have found out that the outer join with a constant value like
to_currency(+)='USD'
to_currency is a column name in a table.can any one please explain this outer join condtn.
Thanks in advance
SenthilHallo,
if you write var (+) = constant
var can be equal constant, and also can be null
Compare these 2 queries
select e.* from scott.emp e, scott.dept d
where e.deptno = d.deptno(+)
and d.deptno(+) = 10EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-Dez-1980 800 20
7499 ALLEN SALESMAN 7698 20-Feb-1981 1600 300 30
7521 WARD SALESMAN 7698 22-Feb-1981 1250 500 30
7566 JONES MANAGER 7839 2-Apr-1981 2975 20
7654 MARTIN SALESMAN 7698 28-Sep-1981 1250 1400 30
7698 BLAKE MANAGER 7839 1-Mai-1981 2850 30
7782 CLARK MANAGER 7839 9-Jun-1981 2450 10
7788 SCOTT ANALYST 7566 19-Apr-1987 3000 20
7839 KING PRESIDENT 17-Nov-1981 5000 10
7844 TURNER SALESMAN 7698 8-Sep-1981 1500 0 30
7876 ADAMS CLERK 7788 23-Mai-1987 1100 20
7900 JAMES CLERK 7698 3-Dez-1981 950 30
7902 FORD ANALYST 7566 3-Dez-1981 3000 20
7934 MILLER CLERK 7782 23-Jan-1982 1300 10
select e.* from scott.emp e, scott.dept d
where e.deptno = d.deptno(+)
and d.deptno = 10 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 9-Jun-1981 2450 10
7839 KING PRESIDENT 17-Nov-1981 5000 10
7934 MILLER CLERK 7782 23-Jan-1982 1300 10
As you can see, this (+) is very important
Regards
Dmytro
Maybe you are looking for
-
Process Code for Outbound Production Order??
Does anybody know the Process Code for Outbound Production Order?? BASIC Type : LOIPRO01 Message Type : LOIPRO Regards, Ravi
-
Cannot change time info on photo PS Elements 13 for Mac
Hello! I took pictures with the date/time stamp on my camera set to the wrong time. When I try to correct the time on the photo under "file info", the time does not stay corrected. Please help! Thank you!
-
Site doesn't show up despite publishing through iWeb
I'm publishing my site to an outside server with IWeb, and though the files are showing up on the server itself, when I attempt to access it from a browser, I constantly get a 404 error. Don't understand why, as all files show in in cpanel. Am using
-
Implemented pagination using JSTL !
Hi, I have implemented pagination using JSTL and uploaded the code at the following website http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4718&lngWId=2Please send feedback on improving the code if any to [email protected] It can
-
My idvd movie dvd's run around 25-28 minutes out of 38 and locks up for about a minute, then goes back to the start menu. This was a Final Cut Express video exported out with quicktime movie to the desktop. It plays through all the way through wi