Sql Joins in the same table
Hi, I have a table (DFO_TRACE) that has two columns CURRENT_FID and SOURCE_FID and I want to find out what are the values that are present in the CURRENT_FID that are not present in the SOURCE_FID for example:
SOURCE_FID | CURRENT_FID
1 | 2
2 | 3
2 | 4
4 | 5
So in the example above I would like to do a select that would return CURRENT_FID = 3 and 5.
I've tried to write the following code to do this, but when I execute it, it doesn't return anything to me:
select A.CURRENT_FID from DFO_TRACE A
left outer join DFO_TRACE B
on A.CURRENT_FID = B.SOURCE_FID
where A.ID_GRUPO_TRACE = 177 and B.ID_GRUPO_TRACE = 177 and B.SOURCE_FID is null;Can anyone help me?
PS: I am using Oracle 10g.
Thanks,
Komyg
The reason you posted query does not work is that the predicate B.ID_GRUPO_TRACE = 177 in the where clause removes all od the "made_up" records from the b version of the table since their id_grupo_trace would be null. You would need to modify your query to something more like:
SELECT a.current_fid
FROM dfo_trace a
LEFT JOIN dfo_trace b
ON a.current_fid = b.source_fid and
a.id_grupo_trace = b.id_grupo_trace
WHERE a.id_grupo_trace = 177 and
b.source_fid IS NULL;John
Similar Messages
-
Two diffferent type of joins on the same table
I have a query that, it seems, requires me to two two different types of joins to the same table.
from table t1
LEFT OUTER JOIN table2 t2
ON t1.col1= t2.col1
and t1.col2 = t2.col2
and t1.col5 = t2.col5
LEFT OUTER JOIN table2 t3
ON t1.col1= t3.col1
and t1.col2 = t3.col2
and t1.col4 = t3.col4
would I run into a problem if I just did:
LEFT OUTER JOIN table2 t2
ON t1.col1= t2.col1
and t1.col2 = t2.col2
and t1.col3 = t2.col3
and t1.col4 = t2.col4
and t1.col5 = t2.col5
And if I go with option 1 and I also create two different types of indexes to accommodate each join, will 10g know which ones to use?
Message was edited by:
user623359
Message was edited by:
user623359No version number and no statement of what it is you are trying to do ... but one solutions is to use the traditional Oracle syntax and the first part, then wraps it in parentheses turning it into an inline view, and then join that to the next part.
-
Multiple joins on the same table
I'm new to SQL 2005 & C# - I'm a MySQL/PHP crossover.
I'm using s Stored Procedure and I'm trying to do multiple joins onto
one table. I have 6 fields in one table that are foreign keys of
another table:
Table1
id
PrimaryCode
SecondaryCode1
SecondaryCode2
SecondaryCode3
SecondaryCode4
SecondaryCode5
Table 2
id
Title
CommCode
The fields in table 1 (except is obviously) hold the id of a row in
Table 2. When displaying data I want to display "Title" -
"CommCode" for each item in Table 1. I got myself started by
searchig on the net and I have a stored procedure. The obvious
problem is that as it goes through the Query only the last value
remains in place - since each value before it is cleared in the
UNION. How can I do this?? Here's my Stored Procedure:
=====================================
ALTER PROCEDURE GetRegistersSpecific
@SearchTxt int
AS
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
PrimaryCode AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON PrimaryCode = CommodityCodes.id
UNION
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
SecondaryCode1 AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON SecondaryCode1 = CommodityCodes.id
UNION
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
SecondaryCode2 AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON SecondaryCode2 = CommodityCodes.id
UNION
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
SecondaryCode3 AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON SecondaryCode3 = CommodityCodes.id
UNION
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
SecondaryCode4 AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON SecondaryCode4 = CommodityCodes.id
UNION
SELECT
registrations.Company,registrations.Address1,registrations.Address2,registrations.City,registrations.State,registrations.Zip,registrations.ContactName,registrations.Phone,registrations.Fax,registrations.Email,registrations.Website,registrations.Feid,registrations.BusinessType,registrations.BackupWitholding,registrations.SignedName,registrations.SignedDate,
SecondaryCode5 AS MyID, Title, CommodityCode
FROM registrations
JOIN CommodityCodes ON SecondaryCode5 = CommodityCodes.id
WHERE registrations.ID = @SearchTxt
=====================================
ThanksWell, I tried using UNION ALL and got the same response. I also tried doing :
Title AS SecTitle1
Title AS SecTitle2
Title AS SecTitle3
etc...
I get different values in the Output Window when I execute the query,
but as expected it only returns the first value since the script
executes all the way through before it outputs values.
Here's how I'm executing:
while (rdr.Read())
// get the results of each column
string company = (string)rdr["Company"].ToString();
string address1 = (string)rdr["Address1"].ToString();
string address2 = (string)rdr["Address2"].ToString();
string city = (string)rdr["City"].ToString();
string state = (string)rdr["State"].ToString();
string zip = (string)rdr["Zip"].ToString();
string phone = (string)rdr["Phone"].ToString();
string fax = (string)rdr["Fax"].ToString();
string email = (string)rdr["Email"].ToString();
string website = (string)rdr["Website"].ToString();
string feid = (string)rdr["Feid"].ToString();
string businessType = (string)rdr["BusinessType"].ToString();
string contactName = (string)rdr["ContactName"].ToString();
string primaryCode = (string)rdr["PrimTitle"].ToString();
string secondaryCode1 = (string)rdr["SecTitle1"].ToString();
string secondaryCode2 = (string)rdr["SecTitle2"].ToString();
string secondaryCode3 = (string)rdr["SecTitle3"].ToString();
string secondaryCode4 = (string)rdr["SecTitle4"].ToString();
string secondaryCode5 = (string)rdr["SecTitle5"].ToString();
string backUp = (string)rdr["BackupWitholding"].ToString();
string signedName = (string)rdr["SignedName"].ToString();
string signedDate = (string)rdr["SignedDate"].ToString(); -
Opinion needed on best way to map multiple table joins (of the same table)
Hi all
I have a query of the format:
select A.col1, B.col1,C.col1
FROM
MASTER_TABLE A, ATTRIBUTE_TABLE B, ATTRIBUTE_TABLE C
WHERE
A.key1 = B.key1 (+)
AND
A.key1 = C.key1(+)
AND
B.key2(+) = 100001
AND
C.key2(+) = 100002
As you can see, I am joining the master table to the attribute table MANY times over, (over 30 attributes in my actual query) and I am struggling to find the best way to map this efficiently as the comparison for script vs. mapping is 1:10 in execution time.
I would appreciate the opinion of experienced OWB users as to how they would tackle this in a mapping and to see if they use the same approach as I have done.
Many thanks
AdiSELECT external_reference, b.attribute_value AS req_date,
c.attribute_value AS network, d.attribute_value AS spid,
e.attribute_value AS username, f.attribute_value AS ctype,
g.attribute_value AS airtimecredit, h.attribute_value AS simnum,
i.attribute_value AS lrcredit, j.attribute_value AS airlimitbar,
k.attribute_value AS simtype, l.attribute_value AS vt,
m.attribute_value AS gt, n.attribute_value AS dt,
o.attribute_value AS datanum, p.attribute_value AS srtype,
q.attribute_value AS faxnum,
R.ATTRIBUTE_VALUE AS FAXSRTYPE,
s.attribute_value AS extno,
t.attribute_value AS tb, u.attribute_value AS gb
v.attribute_value AS mb, w.attribute_value AS stolenbar,
x.attribute_value AS hcredit, y.attribute_value AS adminbar,
z.attribute_value AS portdate
FROM csi_item_instances a,
csi_iea_values b,
csi_iea_values c,
csi_iea_values d,
csi_iea_values e,
csi_iea_values f,
csi_iea_values g,
csi_iea_values h,
csi_iea_values i,
csi_iea_values j,
csi_iea_values k,
csi_iea_values l,
csi_iea_values m,
csi_iea_values n,
csi_iea_values o,
csi_iea_values p,
csi_iea_values q,
CSI_IEA_VALUES R,
csi_iea_values s,
csi_iea_values t,
csi_iea_values u,
csi_iea_values v,
csi_iea_values w,
csi_iea_values x,
csi_iea_values y,
csi_iea_values z
WHERE a.instance_id = b.instance_id(+)
AND a.instance_id = c.instance_id(+)
AND a.instance_id = d.instance_id(+)
AND a.instance_id = e.instance_id(+)
AND a.instance_id = f.instance_id(+)
AND A.INSTANCE_ID = G.INSTANCE_ID(+)
AND a.instance_id = h.instance_id(+)
AND a.instance_id = i.instance_id(+)
AND a.instance_id = j.instance_id(+)
AND a.instance_id = k.instance_id(+)
AND a.instance_id = l.instance_id(+)
AND a.instance_id = m.instance_id(+)
AND a.instance_id = n.instance_id(+)
AND a.instance_id = o.instance_id(+)
AND a.instance_id = p.instance_id(+)
AND a.instance_id = q.instance_id(+)
AND A.INSTANCE_ID = R.INSTANCE_ID(+)
AND a.instance_id = s.instance_id(+)
AND a.instance_id = t.instance_id(+)
AND a.instance_id = u.instance_id(+)
AND a.instance_id = v.instance_id(+)
AND a.instance_id = w.instance_id(+)
AND a.instance_id = x.instance_id(+)
AND a.instance_id = y.instance_id(+)
AND a.instance_id = z.instance_id(+)
AND b.attribute_id(+) = 10000
AND c.attribute_id(+) = 10214
AND d.attribute_id(+) = 10132
AND e.attribute_id(+) = 10148
AND f.attribute_id(+) = 10019
AND g.attribute_id(+) = 10010
AND h.attribute_id(+) = 10129
AND i.attribute_id(+) = 10198
AND j.attribute_id(+) = 10009
AND k.attribute_id(+) = 10267
AND l.attribute_id(+) = 10171
AND m.attribute_id(+) = 10184
AND n.attribute_id(+) = 10060
AND o.attribute_id(+) = 10027
AND p.attribute_id(+) = 10049
AND q.attribute_id(+) = 10066
AND R.ATTRIBUTE_ID(+) = 10068
AND s.attribute_id(+) = 10065
AND t.attribute_id(+) = 10141
AND u.attribute_id(+) = 10072
AND v.attribute_id(+) = 10207
AND w.attribute_id(+) = 10135
AND x.attribute_id(+) = 10107
AND y.attribute_id(+) = 10008
AND z.attribute_id(+) = 10103
AND external_reference ='07920490103'
If I run this it takes less than a second in TOAD, when mapped in OWB it takes ages. 10:1 is a conservative estimate. In reality it takes 15-20 minutes. CSI_IEA_VALUES has 30 million rows CSI_ITEM_INSTANCES has 500,000 rows.
Hope that helps. I would love to know how others would tackle this query. -
Multiple Join over the same table
Hi all,
I have a question concerning joins...
We are working with Oracle 8i.
Consider I have the following tables t_emp_team and t_emp_names
t_emp_team
emp_id1, emp_id2, emp_id3
2, 7, 9
3, 8, 6
4, 11, 3
5, 10, 9
t_emp_names
emp_id, name
2, Peter
3, Mark
4, Liz
5, Will
Now I want a join selecting all the names to the IDs.
My idea was to use a join query like this:
select
a.emp_id1,
a.emp_id2,
a.emp_id3,
b1.name,
b2.name,
b3.name
from
t_emp_team a,
t_emp_names b1,
t_emp_names b2,
t_emp_names b3
where
a.emp_id1=b1.emp_id(+) and
a.emp_id2=b2.emp_id(+) and
a.emp_id3=b3.emp_id(+)
Obviously this is not possible in Oracle as the results are not correct.
Do you have a different idea other than Subselects for each name? (The real table has 16 IDs meaning we would end up with 16 subselects)
Thanks for your help!
-PeterHi,
Obviously this is not possible in Oracle as the results
are not correct.Why do you think so ?
SQL> select
2 a.emp_id1,
3 a.emp_id2,
4 a.emp_id3,
5 b1.name,
6 b2.name,
7 b3.name
8 from
9 t_emp_team a,
10 t_emp_names b1,
11 t_emp_names b2,
12 t_emp_names b3
13 where
14 a.emp_id1=b1.emp_id(+) and
15 a.emp_id2=b2.emp_id(+) and
16 a.emp_id3=b3.emp_id(+)
17 /
 
EMP_ID1 EMP_ID2 EMP_ID3 NAME NAME NAME
4 11 3 Liz Mark
3 8 6 Mark
5 10 9 Will
2 7 9 Peter
 But it would be correct to use normzlized form
of t_emp_team:
SQL> desc t_emp_team_n
Name Null? Type
TEAM_ID NUMBER
EMP_ID NUMBER
 
SQL> select * from t_emp_team_n;
 
TEAM_ID EMP_ID
1 4
1 11
1 3
2 3
2 8
2 6
3 5
3 10
3 9
4 2
4 7
4 9
 
12 rows selected.
 
Elapsed: 00:00:00.04
SQL> select team_id, a.emp_id, name
2 from t_emp_team_n a, t_emp_names b
3 where a.emp_id = b.emp_id (+)
4 order by 1,3
5 /
 
TEAM_ID EMP_ID NAME
1 4 Liz
1 3 Mark
1 11
2 3 Mark
2 8
2 6
3 5 Will
3 10
3 9
4 2 Peter
4 7
4 9
 
12 rows selected.and use the advise of William Robertson:
http://www.williamrobertson.pwp.blueyonder.co.uk/documents/one_row.html
SQL> select team_id, substr(epath,2) "ids",
2 rtrim(substr(npath,2),',') "members"
3 from (
4 select team_id, max(sys_connect_by_path(emp_id,',')) epath,
5 max(sys_connect_by_path(name,',')) npath from (
6 select team_id, a.emp_id, name, row_number()
7 over(partition by team_id order by name nulls last) rn
8 from t_emp_team_n a, t_emp_names b
9 where a.emp_id = b.emp_id (+)
10 )
11 start with rn = 1 connect by prior team_id = team_id
12 and prior rn = rn -1
13 group by team_id
14 )
15 /
 
TEAM_ID ids members
1 4,3,11 Liz,Mark
2 3,8,6 Mark
3 5,10,9 Will
4 2,7,9 PeterRgds. -
Comparing SQL data in the same table for two different dates
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Hello,
We have a batch scheduling tool that automatically runs Oracle jobs and when it runs the jobs it stores a record from the instance in a table. I am trying to write a query that pulls up all of the jobs that ran today and compares them with what ran on the same day last week to find out what jobs didnt run today. So far I have the below but I can't get it to return anything. I am using Toad for this
select *
from xxcar_abat_instances
where trunc(to_date(start_datetime)) = trunc(sysdate-7)
and completion_status = 'Success'
AND NOT EXISTS
(select script_name
from xxcar_abat_instances
where trunc(to_date(start_datetime)) = trunc(sysdate)
and completion_status = 'Success')Thank youHi,
964188 wrote:
It is a date
Such as
10/31/2012 11:55:03 PMThen, as Hoek says, you don't want TO_DATE. For example:
WHERE TRUNC (start_datetime) = TRUNC (SYSDATE - 7) or the more efficient
WHERE start_datetime >= TRUNC (SYSDATE - 7)
AND start_datetime < TRUNC (SYSDATE - 6)Also, it doesn't look like the EXISTS sub-query is corelated to the main query. That's almost certainly a mistake.
If you're still having trouble, post your revised query, a little sample data (CREATE TABLE and INSERT statements). Point out where that query is givimg the wrong results, and explain how to get te right results.
See the forum FAQ {message:id=9360002} -
SQL Developer no longer letting me look at the same table name on 2 servers
I used to be able to look at the same table (such as; "ATS_Reminders") on both my development box and my production box at the same time. Now when I connect to both databases, if I try to open the same table on the second box, the first table closes so I can't look at them side by side. Is there a way to fix this annoying behavior?
I'm on Windows 7 running:
Java(TM) Platform 1.6.0_11
Oracle IDE 3.1.07.42
Versioning Support 3.1.07.42Hi bucketofsquid -
You need to pin the 1st editor. This can be done manually by clicking the freeze view button on the object viewer toolbar or automatically by setting auto freeze on in preferences. Tools->Preferences->Database->ObjectViewer->Automatically Freeze Object Viewer Windows
Brian Jeffries
SQL Developer Team -
SQL error msg - The DELETE statement conflicted with the SAME TABLE REFERENCE constraint
Executed as user: ****. The DELETE statement
conflicted with the SAME TABLE REFERENCE constraint "FK_PARENT_TASK_REF".
The conflict occurred in database "****", table "****", column
'PARENT_TASK_ID'. [SQLSTATE 23000] (Error 547) The statement has been
terminated. [SQLSTATE 01000] (Error 3621). The step failed.
Does this error msg indicate the whole script failed to execute or was it just a single step/task that failed ?
What does error msg mean ?
Anyway to prevent this error msg and ensure script runs successfullyHi mdavidh,
This error occurs because the record 'PARENT_TASK_ID' was referenced by 'FK_PARENT_TASK_REF'.
Please refer below codes:
CREATE TABLE MyTable (
ID INT, primary key(ID), -- primary key
ID_Parent INT foreign key(ID_Parent) references MyTable(ID), -- foreign key reference the same table
insert into MyTable(ID,ID_Parent)
values(0,0);
insert into MyTable(ID,ID_Parent)
values(1,0);
insert into MyTable(ID,ID_Parent)
values(2,0);
insert into MyTable(ID,ID_Parent)
values(3,1);
insert into MyTable(ID,ID_Parent)
values(4,3);
insert into MyTable(ID,ID_Parent)
values(5,4);
CREATE TRIGGER MyTrigger
on MyTable
instead of delete
as
set nocount on
update MyTable set ID_Parent = null where ID_Parent in (select ID from deleted)
delete from MyTable where ID in (select ID from deleted)
Now we could delete records.
delete from MyTable where ID_Parent=0
Thanks,
Candy Zhou -
Multiple and conditions in the same table
Ok I am going to kick myself for this, but I can't figure it out. I am trying to figure out how to find employees which match multiple criteria in the same table.
create table emp
(empno number,
name varchar2(10))
create table skills
(skill_id number,
skill_code varchar2(20))
create table emp_skills
(empno number,
skill_id number,
rating number)
insert into emp values(1, 'SMITH');
insert into emp values(2, 'JONES');
insert into skills values (1, 'SQL');
insert into skills values (2, 'PLSQL');
insert into skills values (3, 'JAVA');
insert into emp_skills values(1,1, 8);
insert into emp_skills values(1,2, 9);
insert into emp_skills values(1,3, 10);
insert into emp_skills values(2,1,9);
insert into emp_skills values(2,2,2);
insert into emp_skills values(2,3,7);Now I need to come up with a query finding all employees who match all 3 of the following criteria:
1) Have at least a 5 rating in SQL
2) Have at least a 6 rating in PLSQL
3) Have at least a 7 rating in JAVA
So using this I would expect to return only SMITH since his/her skills meet all 3 criteria. I dont want to use OR in my query since I want all 3 to match not just one of them.
I have a feeling I will need to self join the table - but this is going to be part of a dynamic query for APEX where the users can choose the skills and ratings they want employees to adhere to, so I dont know the number of criteria or the exact criteria in advance. But I figure if I can get a proof of concept SQL I can make it work dynamically.
Any ideas are appreciated - sorry for the long post but I figure more detail is betterwith es1 as(
select s.skill_code, es.empno, es.rating
from skills s, emp_skills es
where s.skill_id = es.skill_id
/* main */
select e.*
from emp e
where
exists
(select 'x' from es1
where es1.rating >= 5
and es1.skill_code = 'SQL'
and es1.empno = e.empno)
and
exists
(select 'x' from es1
where es1.rating >= 6
and es1.skill_code = 'PLSQL'
and es1.empno = e.empno)
and
exists
(select 'x' from es1
where es1.rating >= 7
and es1.skill_code = 'JAVA'
and es1.empno = e.empno)
-- Addition (Another example)
with es1 as(
select s.skill_code, es.empno, es.rating
from skills s, emp_skills es
where s.skill_id = es.skill_id
/* main */
select e.*
from emp e
where
(select count(distinct es1.skill_code) from es1
where
((es1.rating >= 5 and es1.skill_code = 'SQL')
or
(es1.rating >= 6 and es1.skill_code = 'PLSQL')
or
(es1.rating >= 7 and es1.skill_code = 'JAVA')
and es1.empno = e.empno)
=3; -
How can I connect to Oracle and SQL server at the same time?
I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
[email protected]I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
[email protected]
As far as I know you have 3 options depending on your specifications. I don't think option #3 will work if you need to actually join a
SQL Server table to an Oracle table.
1. Oracle Transparent Gateway. I haven't used the Oracle Transparent Gateway but my understanding is that Oracle gateways are
separate purchased products from Oracle. I've never seen any free/development versions of it anywhere. You'll need to contact
your Oracle sales rep about it.
2. Heterogeneous Connectivity. There's something called Heterogeneous Connectivity that could work for you - depends on what
version of Oracle you're on and what OS. You basically set up an ODBC data source on the Oracle server and modify the listener.ora
and tnsnames.ora files. You can then create a database link to SQL Server just like you would to any other Oracle database. You can
check your Oracle documentation for how this works. There's also some very good documents on Metalink that tell you how to do this
as well as a Heterogeneous Connectivity forum on this site.
3. Use the exec_sql package available in Developer 2000. This allows you to open and execute cursors to remote databases within
Developer. We have an account validation process that uses this - when a person enters an account number in a form while logged
into Oracle it validates the account is valid in our main accounting DB2 database. We also pull HR information from DB2 into Oracle
this way. If you're using Forms 6i exec_sql is a built-in command, in Forms 5.0 and 5.5 you have to add it as an attached library to
the form. I think you also need the OCA options installed from the Developer software to have access to the library in Forms 5.0 and
5.5. The library will be in the $ORACLE_HOME\oca20\plsqllib directory for these versions. The Developer documentation should have
additional information.
HTH -
Historical and transaction data in the same tables creates perf problems
Our Oracle based application is slow partly due to the fact that historical data are kept in the same table as transactional data. For example records about deceased patients, patients treated 5 years ago...etc, are kept in the one and only one patient table, which is needed to run the daily process of the hospital. So gradually all our major tables PATIENTS, CHARTS, NAMES, APPOINTMENTS have grown very large and since most of our SQL join all these tables at the same time, then all screens and reports run very slowly. I have introduced the idea that we should split all these tables in two: historical PATIENTS data, and CURRENT PATIENTS data...the same with all the others. A nice system would first search in the smaller transactional tables, which would run faster being smaller, and if no data found, then fallback to the historical tables. But this would require programming. From what I have read mateialized view could solve part of our problem. We could have views containing for example only one year worth of the data, and I guess any changes could be later replicated in the base table. What I dont know is what to do if we cannot find the patient in the matealized views ? Do I need to fallback to another SQL which will search in the initial base tables ? Anyway we can implement this without programming ? Tx.
Appointment table: 207,470
Visit table: 5,890,920
Patient table: 2,993,129
Chart table: 2,864,069
Patient names table: 3,938,118
SELECT
APPOI_OR_VISIT,
VISIT_SEQ,
PAT_SEQ,
INST_CODE,
INST_CODE_DISPL,
INST_DESC,
CLINIC_CODE,
CLINIC_CODE_DISPL,
CLINIC_DESC,
SPEC_CODE,
SPEC_CODE_DISPL,
SPEC_DESC,
VISIT_DATE,
VISIT_TIME,
VISIT_TIME_ARRIVAL,
APPTYPE_CODE,
SESSION_DOM_MODE,
PRESTYPE_CODE,
PRESTYPE_DOM_TYPE,
DIA_CODE,
VISIT_TIME_START_RESP,
VISIT_TIME_DISCHARGE,
APPOI_NB_DURATION,
VISIT_TX_REASON,
VISIT_TX_COMMENT,
EXTDOC_CODE,
VISIT_PN_REFPHYS_NAME,
PATYPE_CODE,
PAYRESP_CODE,
VISIT_IND_GROUP,
VISIT_PCODE,
VISIT_IND_COMPLETE,
VISIT_IND_ADMISSION,
VISIT_IND_CONFIDENTIALITY,
VISIT_DATE_ACCIDENT,
APPOI_SEQ,
BILLING_CODE,
VISIT_TX_DIAGNOSIS,
CST_CODE_1,
CST_CODE_2,
CST_CODE_3,
APPOI_DH_CRE,
APPOI_CODE_CRE_USER,
APPOI_DH_MOD,
APPOI_CODE_MOD_USER,
VISIT_CODE_CRE_USER,
VISIT_DH_CRE,
VISIT_UPDATED_COUNT,
VISIT_CODE_MOD_USER,
VISIT_DH_MOD,
APPOI_PAYRESP_CODE,
APPOI_DT_ACCIDENT,
PATIENT_LAST_NAME,
PATIENT_FIRST_NAME,
PATIENT_CONFIDENTIALITY,
PATIENT_CHART_EXT,
TO_NUMBER(SUBSTR(PATIENT_CHART_EXT, 1, INSTR(PATIENT_CHART_EXT, '|')-1)) AS PATIENT_CHART_NO,
PAT_IND_SPECIAL_RISK
FROM
SELECT
'VISIT' AS APPOI_OR_VISIT,
VISIT.VISIT_SEQ,
VISIT.PAT_SEQ,
INSTITUTION.INST_CODE,
INSTITUTION.INST_CODE_DISPL,
INSTITUTION.INST_DESC,
CLINIC.CLINIC_CODE,
CLINIC.CLINIC_CODE_DISPL,
CLINIC.CLINIC_DESC,
SPECIALTY.SPEC_CODE,
SPECIALTY.SPEC_CODE_DISPL,
SPECIALTY.SPEC_DESC,
VISIT.VISIT_DATE,
VISIT.VISIT_TIME,
VISIT.VISIT_TIME_ARRIVAL,
VISIT.APPTYPE_CODE,
VISIT.SESSION_DOM_MODE,
VISIT.PRESTYPE_CODE,
VISIT.PRESTYPE_DOM_TYPE,
VISIT.DIA_CODE,
VISIT.VISIT_TIME_START_RESP,
VISIT.VISIT_TIME_DISCHARGE,
VISIT.APPOI_NB_DURATION,
VISIT.VISIT_TX_REASON,
VISIT.VISIT_TX_COMMENT,
VISIT.EXTDOC_CODE,
VISIT.VISIT_PN_REFPHYS_NAME,
VISIT.PATYPE_CODE,
VISIT.PAYRESP_CODE,
VISIT.VISIT_IND_GROUP,
VISIT.VISIT_PCODE,
VISIT.VISIT_IND_COMPLETE,
VISIT.VISIT_IND_ADMISSION,
VISIT.VISIT_IND_CONFIDENTIALITY,
VISIT.VISIT_DATE_ACCIDENT,
VISIT.APPOI_SEQ,
VISIT.BILLING_CODE,
VISIT.VISIT_TX_DIAGNOSIS,
VISIT.CST_CODE_1,
VISIT.CST_CODE_2,
VISIT.CST_CODE_3,
VISIT.APPOI_DH_CRE,
VISIT.APPOI_CODE_CRE_USER,
VISIT.APPOI_DH_MOD,
VISIT.APPOI_CODE_MOD_USER,
VISIT.VISIT_CODE_CRE_USER,
VISIT.VISIT_DH_CRE,
VISIT.VISIT_UPDATED_COUNT,
VISIT.VISIT_CODE_MOD_USER,
VISIT.VISIT_DH_MOD,
NULL AS APPOI_PAYRESP_CODE,
TO_DATE(NULL) AS APPOI_DT_ACCIDENT,
NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(VISIT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
PATIENT.PAT_IND_SPECIAL_RISK
FROM
AS_T_VISITS VISIT,
CT_R_INSTITUTIONS INSTITUTION,
AS_T_CLINICS CLINIC,
CT_R_SPECIALITIES SPECIALTY,
PI_T_NAMES NAME,
PI_T_PATIENTS PATIENT,
PI_R_CONF_LEVELS CONFIDENTIALITY
WHERE
VISIT_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
VISIT_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
CLINIC.CLINIC_CODE = VISIT.CLINIC_CODE AND
SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
INSTITUTION.INST_CODE(+) = VISIT.INST_CODE AND
NAME.PAT_SEQ = VISIT.PAT_SEQ AND
NAME.NAMTYP_CODE = 1 AND
PATIENT.PAT_SEQ = VISIT.PAT_SEQ AND
CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE
UNION
SELECT
'APPOI' AS APPOI_OR_VISIT,
0 AS VISIT_SEQ,
NVL(APPOINTMENT_GROUP.PAT_SEQ, APPOINTMENT.PAT_SEQ) AS PAT_SEQ,
INSTITUTION.INST_CODE,
INSTITUTION.INST_CODE_DISPL,
INSTITUTION.INST_DESC,
CLINIC.CLINIC_CODE,
CLINIC.CLINIC_CODE_DISPL,
CLINIC.CLINIC_DESC,
SPECIALTY.SPEC_CODE,
SPECIALTY.SPEC_CODE_DISPL,
SPECIALTY.SPEC_DESC,
APPOINTMENT.SESSION_DATE AS VISIT_DATE,
APPOINTMENT.APPOI_TIME AS VISIT_TIME,
'' AS VISIT_TIME_ARRIVAL,
APPOINTMENT.APPTYPE_CODE,
APPOINTMENT.SESSION_DOM_MODE,
0 AS PRESTYPE_CODE,
'' AS PRESTYPE_DOM_TYPE,
0 AS DIA_CODE,
'' AS VISIT_TIME_START_RESP,
'' AS VISIT_TIME_DISCHARGE,
APPOINTMENT.APPOI_NB_DURATION,
APPOINTMENT.APPOI_TX_REASON AS VISIT_TX_REASON,
APPOINTMENT.APPOI_TX_COMMENT AS VISIT_TX_COMMENT,
APPOINTMENT.EXTDOC_CODE,
APPOINTMENT.APPOI_PN_REFPHYS_NAME AS VISIT_PN_REFPHYS_NAME,
APPOINTMENT_TYPE.PATYPE_CODE AS PATYPE_CODE,
0 AS PAYRESP_CODE,
DECODE(APPOINTMENT_GROUP.PAT_SEQ,NULL,0,1) AS VISIT_IND_GROUP,
'' AS VISIT_PCODE,
0 AS VISIT_IND_COMPLETE,
0 AS VISIT_IND_ADMISSION,
APPOINTMENT.APPOI_IND_CONFIDENTIALITY AS VISIT_IND_CONFIDENTIALITY,
TO_DATE(NULL) AS VISIT_DATE_ACCIDENT,
APPOINTMENT.APPOI_SEQ,
0 AS BILLING_CODE,
'' AS VISIT_TX_DIAGNOSIS,
0 AS CST_CODE_1,
0 AS CST_CODE_2,
0 AS CST_CODE_3,
APPOINTMENT.APPOI_DH_CRE AS APPOI_DH_CRE,
APPOINTMENT.APPOI_CODE_CRE_USER AS APPOI_CODE_CRE_USER,
APPOINTMENT.APPOI_DH_MOD AS APPOI_DH_MOD,
APPOINTMENT.APPOI_CODE_MOD_USER AS APPOI_CODE_MOD_USER,
'' AS VISIT_CODE_CRE_USER,
SYSDATE AS VISIT_DH_CRE,
0 AS VISIT_UPDATED_COUNT,
'' AS VISIT_CODE_MOD_USER,
SYSDATE AS VISIT_DH_MOD,
PAYRESP_CODE AS APPOI_PAYRESP_CODE,
APPOI_DT_ACCIDENT,
NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(APPOINTMENT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
PATIENT.PAT_IND_SPECIAL_RISK
FROM
AS_T_APPOINTMENTS APPOINTMENT,
AS_R_APPOINTMENT_TYPES APPOINTMENT_TYPE,
AS_T_CLINICS CLINIC,
CT_R_SPECIALITIES SPECIALTY,
CT_R_INSTITUTIONS INSTITUTION,
AS_T_APPOINTMENT_GROUPS APPOINTMENT_GROUP,
PI_T_PATIENTS PATIENT,
PI_R_CONF_LEVELS CONFIDENTIALITY,
PI_T_NAMES NAME,
AS_T_APPOINTMENT_SEQ_MAPPING SEQMAP
WHERE
SESSION_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
SESSION_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
APPOINTMENT.APPOI_DOM_TYPE IN('A','AR') AND
CLINIC.CLINIC_CODE = APPOINTMENT.CLINIC_CODE AND
SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
INSTITUTION.INST_CODE(+) = APPOINTMENT.INST_CODE AND
APPOINTMENT_GROUP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
APPOINTMENT_TYPE.APPTYPE_CODE (+) = APPOINTMENT.APPTYPE_CODE AND
NAME.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
NAME.NAMTYP_CODE = 1 AND
PATIENT.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE AND
SEQMAP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
SEQMAP.APPOI_SEQ IS NULL
ORDER BY
VISIT_DATE, VISIT_TIME, PATIENT_CHART_NO -
Illegal cross join within the same dimension caused by incorrect subject ar
hi!
Imagine the following BMM:
There is one Logical Dimension Table "Service Account" with the following LTS:
- LTS "D_SERVICE"
- LTS "D_SERVICE_CLASS"
- LTS "D_SERVICE_STATUS"
This Logical Tabe "Service Account" joins (One-to-many) with several Fact Tables (other Logical Tables).
In the Physical Layer the joins for the "Service Account" LTS are:
- One-to-many between D_SERVICE_CLASS and D_SERVICE
- One-to-many between D_SERVICE_STATUS and D_SERVICE
The problem is that when I build a report in Answers using only the following columns of the Logical Table "Service Account":
- Service Class Desc (which exists in the Logical Table "Service Account" and in the Physical Table D_SERVICE_CLASS)
- Service Status Desc (which exists in the Logical Table "Service Account" and in the Physical Tabl D_SERVICE_STATUS)
- MSISDN (which existis in the Logical Table "Service Account" and in the Phsyical Table D_SERVICE)
the following error appears:
Estado: HY000. Código: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ (select * from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) as T1836, D_SERVICE_CLASS T1916] with [ D_SERVICE_STATUS T1948] (HY000)
SQL emitido: SELECT "SERVICE ACCOUNT"."TLC MSISDN9" saw_0, "SERVICE ACCOUNT"."IWS Service Class Desc" saw_1, "SERVICE ACCOUNT"."TLC Service Status Desc" saw_2 FROM "VFPT - Upgrade Siebel" WHERE "SERVICE ACCOUNT"."TLC MSISDN9" = '917330340' ORDER BY saw_0, saw_1, saw_2
Help, please!
Thanks.Physically, only D_SERVICE is joined to the facts. Then D_SERVICE_CLASS is joined to D_SERVICE (one-to-many) and D_SERVICE_STATUS is joined also to D_SERVICE (one-to-many).
In the BMM, there is only one Logical Dimension Table for those 3 physical tables. This Logical Dimension Table is called "Service Account" and has 3 LTS: D_SERVICE, D_SERVICE_CLASS, D_SERVICE_STATUS. The Logical Dimension Table has several logical columns that are associated to those 3 LTS: SERVICE_KEY, SERVICE_CLASS_KEY, SERVICE_STATUS_KEY, SERVICE_MSISDN, SERVICE_CLASS_DESC, SERVICE_STATUS_DESC.
The Logical Dimension Table "Service Account" is then joined to a fact table (one-to-many).
I didn't understand the suggestion about the 3 LTS... Aren't we doing that already? Can you explain it better, please?
thanks. -
UPDATE involving the same table in sub query
DB version: 11.2
We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
UPDATE shp_gc_track a
SET f_tran_proc = 'Y'
WHERE last_update_date <
(SELECT MAX (last_update_date)
FROM shp_gc_track b
WHERE a.shp_trx_rowid = b.shp_trx_rowid
AND a.c_shp_inst = b.c_shp_inst
AND a.f_tran_proc = b.f_tran_proc
AND b.f_ltr_received = 'D'
AND f_rec_code IN ('G', 'W')
AND b.f_rec_status = 'B'
AND b.c_shp_inst = :b1
AND a.c_shp_inst = :b1
AND a.f_ltr_received = 'D' -----------------> part of composite index
AND a.f_tran_proc = 'N' -----------------> part of composite index
AND a.f_rec_code IN ('G', 'W') --------------> part of composite index
AND a.f_rec_status = 'B'; -----------------> part of composite index This UPDATE takes a long time to execute and sometime get hung.
We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
Is there anyway to rewrite this query or any other suggestions ?Steve_74 wrote:
DB version: 11.2
We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
UPDATE shp_gc_track a
SET f_tran_proc = 'Y'
WHERE last_update_date <
(SELECT MAX (last_update_date)
FROM shp_gc_track b
WHERE a.shp_trx_rowid = b.shp_trx_rowid
AND a.c_shp_inst = b.c_shp_inst
AND a.f_tran_proc = b.f_tran_proc
AND b.f_ltr_received = 'D'
AND f_rec_code IN ('G', 'W')
AND b.f_rec_status = 'B'
AND b.c_shp_inst = :b1
AND a.c_shp_inst = :b1
AND a.f_ltr_received = 'D' -----------------> part of composite index
AND a.f_tran_proc = 'N' -----------------> part of composite index
AND a.f_rec_code IN ('G', 'W') --------------> part of composite index
AND a.f_rec_status = 'B'; -----------------> part of composite index This UPDATE takes a long time to execute and sometime get hung.
We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
Is there anyway to rewrite this query or any other suggestions ?Tuning updates with subqueries can be hard :(. Sadly my suggestions below are of the try-it-and-see-what-happens variety - nothing certain
First, check the index. Is it bitmap or b-tree? If b-tree see if the most restrictive columns are listed first - this can help with b-tree index efficiency. Also if b-tree a composite bitmap for columns with lots of repeating values instead might help
Its a correlated subquery so you can't just run the subquery first putting the result into a scalar varaiable and using the variable in the SQL instead. You can try putting the results of the subuqery w/join keys in a GTT first using the GTT in the SQL to see if I/O is reduced overall during both operations.
Do you have the licence for the parallel query option? Using parallel DML (this must be turned on manually) might help. Check the docs for the ALTER SESSION command to do this. Also, the PARALLEL_INDEX() hint might help
Post the execution plan of the SQL -
[nQSError: 14065] Illegal cross join within the same dimension
Hey guys,
I'm stumped. I have two dimension tables that are joined 1:N (there is NOT an M:N relationship between them) and I have them joined in the Physical Layer and the Business Model and Mapping Layer. The two tables are F4101 (the "1") and F4102 (the "N") in the 1:N relationship. F4102 then joins to a fact table, and F4101 joins to NOTHING else. So I don't believe I have a circular condition or a need for a bridge table. Both tables are published to the Presentation Layer for reporting.
The error occurs in Answers when I want to do something as trivial as display the three primary key columns together from F4101: F4101.col1, F4101.col2, F4101.col3 (all three make up the PK). When I do that, the following error occurs:
"nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ F4101 T28761] with [ F4102 T1805] "
What I can't figure out is WHY the F4102 table is listed in this error. I didn't try to report on it at all. See the logical SQL below from my query:
"SQL Issued: SELECT "Item Master (F4101)".IMITM saw_0, "Item Master (F4101)".IMLITM saw_1, "Item Master (F4101)".IMAITM saw_2 FROM "Sales Analysis" ORDER BY saw_0, saw_1, saw_2"
As soon as I take out one of the three PK columns and add in another non-PK column from F4101, it works just fine. And reporting on each of the three PK columns individually works as well in Answers.
Any ideas? I would greatly appreciate it.
Thanks.Try this;
1. In the logical layer, create one folder called F4101_F4102.
2. Map both F4101 and F4102 as logical table sources in that folder.
3. Join from the folder F4101_F4102 to the fact using a Logical (new complex join) join.
Chris. -
Illegal cross join within the same dimension
Hi,
When certain fields are selected within the presentation table an "illegal cross join" error is returned by the BI Server. However if a FACT is added from one of the other presentation tables the "illegal cross join" error goes away. we need to query without fact column.
We are getting following error
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ CALL_CENTER.COUNSELOR_MANAGER T782130] with [ CALL_CENTER.COUNSELOR_HR T781594 On CALL_CENTER.COUNSELOR_HR.MASTER_STAFF_COUNSELOR_ID = CALL_CENTER.MASTER_STAFF_COUNSELOR.MASTER_STAFF_COUNSELOR_ID, CALL_CENTER.MASTER_STAFF_COUNSELOR T781739] (HY000)
Can anybody help me solving this issue.
Thanks,
KS.Please give us an example of what you need.
OBIEE perform a query in the dimension or through the fact table.
You can't join two dimensions in the repository without going through a fact table.
If you need to query without fact column, it's because you have design two dimensions where
normally you can do one.
You have then two solutions :
* change the design of your logical model to make only one dimension.
* use the OBIEE logical SQL in answer.
http://gerardnico.com/wiki/dat/obiee/bi_server/design/obiee_logical_sql
Success
Nico
Maybe you are looking for
-
How to show the dialogs in Indesign?
hi to all, I tried these script to show the dialogs but it doesn't work at all! $.writeln(app.dialogs.length); app.dialogs.everyItem().destroy(); //for(var i=0;i<app.dialogs.length;i++) // app.dialogs[i].destroy(); //These also i tr
-
Effects and sharing questions.
First off, is there a way to make a clip play slower or faster than normal? I want to make some clips look like the event was taking forever so we had to speed things up and clips with events that need to be played in slow motion. Also, what is the b
-
[Solved]Catalyst14.1 and X server1.15, X crashed when playing video
Last upgrade to catalyst 14.1-1 and xorg-server 1.15.0 When playing local video,the X server crashed.Nothing's wrong unless playing local video,Watching online video and ingame video ,as well as playing video in Vmware has nothing wrong.I've tried vl
-
Hi All, I just started learning ABAP. Can any one suggest me documents/ Help docs. Thanks, Anitha.B
-
I inserted a few FLV videos into my html and I can't seem to get them to play. Basically, I just went to "insert" > "media" > "FLV..." I checked all the paths in the code, can anyone see something wrong with the code? thanks... http://www.hopelightwo