Doubt in joins
hi,
i have four tables tab1,tab2,tab3,tab4
tab1(columns are name,timestamp,id)
name, timestamp ,id
name1 5/28/2007 12:45:18 PM 01
name2 5/28/2007 12:44:18 PM 02
name3 5/28/2007 12:43:18 PM 03
name4 5/28/2007 12:43:18 PM 04
name 5 5/28/2007 12:42:18 PM 05
name6 5/28/2007 12:41:18 PM 06
name7 5/28/2007 12:40:18 PM 07
name8 5/28/2007 12:39:18 PM 08
name9 5/28/2007 12:38:18 PM 09
name10 5/28/2007 12:37:18 PM 10
in tab2(columns are id and value)
id , value
01 10
04 11
08 22
09 33
in tab3(columns are id and value)
id , value
02 99
03 66
05 77
in tab4(columns are id and value)
id , value
06 99
07 77
10 88
the id in tab1 may be in tab2 or tab3 or tab4
i have to get all the ids value in tab2,tab3,tab4 in relation with tab1(table) depending o max(timestamp)- 5 minutes
means
tab1 id == tab2 id then value of tab2 or
tab1 id == tab3 id then value of tab3 or
tab1 id== tab4 id then value of tab4 and also
tab1 timestamp=max(timestamp)-5/1440 (last 5 minutes entries from latest entry time)
how can i write the querty
please help
Message was edited by:
user566456
Please, clarify this:
tab1 timestamp=max(timestamp)-5/1440 (last 5
minutes entries from latest entry time)what do you want to do with timestamp clolumn?
SQL> with tab1 as (select 'name1' name, to_date('5/28/2007 12:45:18' , 'mm/dd/yyyy hh24:mi:ss') timestamp, 01 id from dual union all
2 select 'name2', to_date(' 5/28/2007 12:44:18' , 'mm/dd/yyyy hh24:mi:ss'), 02 from dual union all
3 select 'name3', to_date(' 5/28/2007 12:43:18' , 'mm/dd/yyyy hh24:mi:ss'), 03 from dual union all
4 select 'name4', to_date(' 5/28/2007 12:43:18' , 'mm/dd/yyyy hh24:mi:ss'), 04 from dual union all
5 select 'name5', to_date(' 5/28/2007 12:42:18' , 'mm/dd/yyyy hh24:mi:ss'), 05 from dual union all
6 select 'name6', to_date(' 5/28/2007 12:41:18' , 'mm/dd/yyyy hh24:mi:ss'), 06 from dual union all
7 select 'name7', to_date(' 5/28/2007 12:40:18' , 'mm/dd/yyyy hh24:mi:ss'), 07 from dual union all
8 select 'name8', to_date(' 5/28/2007 12:39:18' , 'mm/dd/yyyy hh24:mi:ss'), 08 from dual union all
9 select 'name9', to_date(' 5/28/2007 12:38:18' , 'mm/dd/yyyy hh24:mi:ss'), 09 from dual union all
10 select 'name10', to_date(' 5/28/2007 12:37:18' , 'mm/dd/yyyy hh24:mi:ss'), 10 from dual),
11 tab2 as (select 01 id, 10 value from dual union all
12 select 04, 11 from dual union all
13 select 08, 22 from dual union all
14 select 09, 33 from dual),
15 tab3 as (select 02 id, 99 value from dual union all
16 select 03, 66 from dual union all
17 select 05, 77 from dual),
18 tab4 as (select 06 id, 99 value from dual union all
19 select 07, 77 from dual union all
20 select 10, 88 from dual)
21 --
22 select tab1.*,
23 greatest(nvl(tab2.value,0), nvl(tab3.value,0), nvl(tab4.value,0)) value,
24 case when tab2.value is not null then tab2.value
25 when tab3.value is not null then tab3.value
26 when tab4.value is not null then tab4.value
27 end value_case
28 from tab1, tab2, tab3, tab4
29 where tab1.id = tab2.id(+)
30 and tab1.id = tab3.id(+)
31 and tab1.id = tab4.id(+)
32 /
NAME TIMESTAMP ID VALUE VALUE_CASE
name1 28.05.2007 1 10 10
name4 28.05.2007 4 11 11
name8 28.05.2007 8 22 22
name9 28.05.2007 9 33 33
name5 28.05.2007 5 77 77
name3 28.05.2007 3 66 66
name2 28.05.2007 2 99 99
name10 28.05.2007 10 88 88
name6 28.05.2007 6 99 99
name7 28.05.2007 7 77 77
10 rows selected
Similar Messages
-
Hi,
cant get this thing off from me :-)....so please dont get annoyed...
Still the same childish doubt got into me after discussion with a friend of mine....
(and ghosh i dont have the tkprof or such settings with me to test the sequence)...
select a.col1, b.col1,c.col1
from a,b,c
where a.col1 = b.col2
and a.col1 = c.col3
and a.col1 < 10;
how will the parser execute this??
one opinion
A)
1.select all the columns from a,b,c and create complete cross joins between them
2. apply the filter a.col1<10 first as it comes last in where clause ( dont think this is no longer valid for CBO )
3. apply second join condition and filter
4. apply first join condition
5. release the result sets
second opinin
B)
1. select table c and make it driving table (valid for CBO???!!!)
2. select table b and make a cross join with b
3. select table a and first filter a.col1<10 then join with the above cross-joined-resultset based on the join conditions
4. pass the final res
confused!!!??
(Michels has already cleared the doubt in one of the posts , but still I got 2 different opinion from people who are experienced ....)
so just wanted to take a final confirmed opinion thats all
s
Message was edited by:
user571638First off:
2. apply the filter a.col1<10 first as it comes last in where clause ( dont think this is no longer valid for CBO )
This was never valid. Even the RBO had more sense than to just work blindly through the WHERE predicates in a fixed order.
Also,
> 5. release the result sets
is not really right - if possible it will begin to stream rows back to you before it has fetched them all, whereas the above description makes it look as though it gathers all the results up in some temporary store before passing them all back at once.
Regarding the optimizer's joining strategy, any permutation and ordering is possible including cross joins, although it has various strategies that mean it does not have to work through every conceivable permutation. It will try various approaches, calculate their costs, and pick the one it thinks is going to be most efficient. -
Doubt regarding joins in obiee
hi gems...
i have a doubt regarding BI analytics join.
When i have imported all the tables from my schema in the repository, then it got imported with all the joins defined in the database.
then i made several business models and create some reports.
there i got some errors, which are mainly due to self join in the tables and more than one joins between two tables.
my question is...are these two types of joins not supported in obiee???
and if i want more than one join condition between two tables, then what can i do???
thanks in advance...Hi User,
OBIEE doesnot support self join. To avoid such circular joins ,make use of alias tables in the physical layer.The following is a list of the main reasons to create an alias table:
To reuse an existing table more than once in your physical layer (without having to import it several times.
To set up multiple alias tables, each with different keys, names, or joins.
To help you design sophisticated star or snowflake structures in the business model layer. Alias tables are critical in the process of converting ER Schemas to Dimensional Schemas
Rgds,
Dpka -
Doubt in Joins - 1Z0-051 Preparation
Hi,
In Chapter 7, p.no 317 of 'OCA Oracle Databse 11g, SQL Fundametals I Exam Guide' regarding the joins, there is below lines.
If no joins are N-1 joins are specified in the WHERE clause conditions, where N refers to the number of tables in the query, then a cartesian or cross join is performed.
If an adequate number of joins conditions are specified, then the first optional conditional clause specifies a natural join, while the second two optional clauses specify the syntax for right and left outer joins.I didnt quite understand this well. For ex.
select regions.region_name , countries.countries_name from regions , countries where regions.region_id = countries.region_id.
Countries table has coutry_id , country_name, region_id.
Regions table has region_id, region_name.In the above case, it is a natural join, But as per the lines from book, it has N-1 (2-1) joins in the where clause, so this is a cartesian or cross join.
I might be wrong in uderstanding it clearly.
Can anyone help me in understanding those 2 lines regarding the joins.
Thanks in advance. :-)agathya wrote:
If no joins are N-1 joins are specified in the WHERE clause conditions, where N refers to the number of tables in the query, then a cartesian or cross join is performed.Hmm... Might be a printing mistake. If there are less than n-1 join conditions or if there are no joins, then the result will be a Cartesian Product or what you consider as CROSS JOIN.
The number of rows in a Cartesian product is equal to the product of number of rows in the first table and number of rows in the second table and the number of rows in the third table. In the following example it will be 5*2*3 = 30 rows.
SQL> set feedback on;
SQL> SELECT * FROM test_tab_1
2 /
COL_1
1
2
3
4
5
5 rows selected.
SQL> SELECT * FROM test_tab_2
2 /
COL_2
1
2
3
3 rows selected.
SQL> SELECT * FROM test_tab_3
2 /
COL_3
1
2
2 rows selected.
SQL> SELECT a1.*, a2.*, a3.*
2 FROM test_tab_1 a1, test_tab_2 a2, test_tab_3 a3
3 /
COL_1 COL_2 COL_3
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
1 2 1
2 2 1
3 2 1
4 2 1
5 2 1
1 3 1
COL_1 COL_2 COL_3
2 3 1
3 3 1
4 3 1
5 3 1
1 1 2
2 1 2
3 1 2
4 1 2
5 1 2
1 2 2
2 2 2
COL_1 COL_2 COL_3
3 2 2
4 2 2
5 2 2
1 3 2
2 3 2
3 3 2
4 3 2
5 3 2
30 rows selected.The following code gives a demonstration where you will have less than N-1 Joins (In this case you should have 2 Joins to avoid Cartesian Product). In this case it will be the resultant of the join conditions between test_tab_1 and test_tab_3 multiplied by the number of rows in the unjoined table (test_tab_3)
SQL> SELECT a1.*, a2.*, a3.*
2 FROM test_tab_1 a1, test_tab_2 a2, test_tab_3 a3
3 WHERE a1.col_1 = a2.col_2
4 /
COL_1 COL_2 COL_3
1 1 2
1 1 1
2 2 2
2 2 1
3 3 2
3 3 1
6 rows selected.
SQL>Hope this helps,
The example mentioned above assumes that there is 1 to 1 relationship between the three tables.
Regards,
Jo -
Doubt on Join Mapping documentation
Dear all,
Let me present the following case: I'm working against an Oracle database where I have two tables ASSET (id NUMBER, name VARCHAR2, asset_type_id NUMBER) and ASSET_TYPE (id NUMBER, type_name VARCHAR2).
What I want to try is to build an Asset.cfc with the id (numeric), name (string), and typeName (string) properties. I tried to avoid having an AssetType class loaded into the type property that later I had to access with asset.getType().getTypeName(), but having the typeName string directly as asset.getTypeName().
Then I read the "Join mapping in a CFC" section of the CF9 documentation and thought to have found an elegant solution. The document presents the Employee-Address relationship and uses the addressId joincolumn, but never explains if the addressId column is member of the Employee or the Address table. I guessed the addressId was a column of the Employee table pointing to the PK of the Address table, and tried to apply that logic to my case; of course, it does not work. Then I reached the conclusion that the addressId must be a member of Address table that maps automatically always to the PK of the Employee table.
(1) Is my conclusion right? I.e. is the joincolumn a member of the target table and joins always automatically to the defined PK of the source table? If this is the case, I cannot solve my problem this way as I want to join the target id column with the source asset_type_id column.
(2) Is there a way to override this and make the joincolumn to join to an alternative source column other than the PK?
(3) Does anyone knows the why of this limitation?
(4) Could anyone explain an alternative way for getting the type string directly with asset.getType() without creating an explicit AssetType cfc? Is there some pattern or best practice for this case?
Sorry for the long post and thanks in advance for your help.
Regards,
JesúsOk,
A solution seems to be the @formula parameter (sorry I didn't find the http://forums.adobe.com/message/2298153#2298153 post before). Any solution using the join mapping? (I guess not). Any other ideas?
Just one question for the experts: if I use the formula for several properties calculated from the same table, does hibernate intelligently translate them to a single query?
Thanks,
Jesús -
Hello experts,
I have Selection screen with ausp-atwrt,lips-werks,likp-vstel,etc.
Output fields are lips-matnr,lips-lfimg,
ausp-atwrt,likp-lgort,likp-wadat_ist.
I need to get output I am trying to join lips likp ausp.
Can any body suggest me.
ThanksHi Nitin
Try getting data into separate int tables, process it and output by populating the processed data into one output internal table.
Pl Reward if it helps
K -
Doubt in attribute view on joining the table .
Hello Team
Can some please help me in clearing the following doubts on joining tables .
i) Can we perform a self join in attribute view in HANA . like for ex :- joining a table to itself .
ii)Can we create an analytic view without creating an attribute view i.e creating an analytic view directly on tables .
iii)When aggregation happens in calculation view exactly what happens internally .
Please suggest me with the solution of these doubts .
RegardsHi Prag,
As Rashmi has answered your question, i would like to add up to it few more important points.
1. Do not perform self join as it will return uncertain results. It is better to avoid self join.
You can create a copy of the same table and perform join which will be consistent.
2. In an analytic view, you will be adding table to data foundation, select the output fields.In the logical join node by default your data foundation will be present (this will contain the fields that you selected for output), you need not add any attribute view to this logical join node, leave it to default. In the semantics node select the attributes and measures. Perform validation and then activate. Your analytic view without attribute view is ready. You can check the data preview.
3. In a calculation view, the records gets grouped by all the attributes and then the measures are calculated based on this grouping by using the mentioned aggregation (sum/max/min).
Eg.
Customer ID 0Calmonth Amount (aggregation = max)
1001 01.2014 100
1001 01.2014 400
1002 01.2014 200
Output:
Customer ID 0Calmonth Amount (aggregation = max)
1001 01.2014 400
1002 01.2014 200
Hope this clarifies your doubts.
Thanks and Regards,
M.N.Adinarayanan -
Joins with multiple fact tables
Hi Experts,
i have one doubt in joins
we have two dimensions D1 and D2,
D1 is having A1 and A2 columns
D2 is having B1 and B2 columns
two facts F1 and F2 these are joined like D1 to F1 D1 to F2 and D2 to F1, D2 to F2
D1----->F1
D1------>F2
D2-------->F1
D2-------->F2
if i selected A1 and B1 in a request from which FACT table will get the data and why can you please explain
please help me
reg,
JellHi All,
I have a similar requirement where I have 4 multiple fact tables and we can't combine all those facts into one single fact table. In that case how can a query work with multiple common and uncommon dimensions and measures from multiple fact tables, if it doesn't work that way - can you please explain how can we expect a query to work with multiple fact tables.
For eg: D1– Dim
D2 – Dim
D3 – Dim
D4 – Dim
F1 –Fact
F2 – Fact
F3 – Fact
D1 -> F1
D2 -> F1,F2
D3 -> F2
D4 -> F1, F3
In this case if we want to query from D1,D2,D3, F1, F2 or D1,D2,D3,D4,F1,F2,F3. Kindly please explain how it can be modeled in BMM or what are the limitations. I have done with two fact tables in past and didn't had issues but this is kind of a vast implementation. Your help is appreciated. -
I ordered a phone line to be installed a couple of weeks ago and today(25/7/12) was the installation date(supposedly). I've taken the day off work and had to stay in all Morning waiting for an engineer to come between 8am and 1pm. Come 12 I called to see where the engineer was and after being put on hold numerous times was told there was an external problem with the exchange. Have now been told an engineer will (hopefully) be out on 06/08/12 to install the line. Thanks for wasting my day BT and keeping me informed! Already having doubts about joining BT
BT do not provide or maintain the external network. This is done by Openreach who work for all service providers. BT do not get any special treatment.
Openreach are having difficulties due to the recent bad weather, so installation and repairs are taking much longer than normal.
There are some useful help pages here, for BT Broadband customers only, on my personal website.
BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones. -
Urgent : Doubt on creating joins
Hi friends,
I have two tables , ekes and eine
my requirement is if Ekes-ebtyp = 'X1'.
then Ekes-ebtyp = EKES-EINDT + Eine-j_3alitra.
the doubt is there is no primary key common between this table . actually in my whole program for purchase order i used EBELN for extracting details when two tables are involved . in this two tables no two primary keys are common to extract data ...is there any ways please suggest..
the code i wrote is
loop at li_ekes assigning <fl_ekes>.
read table li_eine assigning <fl_eine> with table key (here i need to give some unique fields to join these two fields please guide me which field i can use.).
<fl_ekes>-ebtyp = <fl_ekes>-EINDT + <fl_eine>-j_3alitra.Hi Gokul try this one,
ekes-ebeln = eine-anfnr
ebes-ebelp = eine-anfps
Make join on this condition it will work.
Reward if it is useful. -
Hi friends,
I have two tables , ekes and eine
my requirement is if Ekes-ebtyp = 'X1'.
then Ekes-ebtyp = EKES-EINDT + Eine-j_3alitra.
the doubt is there is no primary key common between this table . actually in my whole program for purchase order i used EBELN for extracting details when two tables are involved . in this two tables no two primary keys are common to extract data ...is there any ways please suggest..
the code i wrote is
loop at li_ekes assigning <fl_ekes>.
read table li_eine assigning <fl_eine> with table key (here i need to give some unique fields to join these two fields please guide me which field i can use.).
<fl_ekes>-ebtyp = <fl_ekes>-EINDT + <fl_eine>-j_3alitra.Hi Gokul try this one,
ekes-ebeln = eine-anfnr
ebes-ebelp = eine-anfps
Make join on this condition it will work.
Reward if it is useful. -
Doubt on creating join between two tables
Hi friends,
I have two tables , ekes and eine
my requirement is if Ekes-ebtyp = 'X1'.
then Ekes-ebtyp = EKES-EINDT + Eine-j_3alitra.
the doubt is there is no primary key common between this table . actually in my whole program for purchase order i used EBELN for extracting details when two tables are involved . in this two tables no two primary keys are common to extract data ...is there any ways please suggest..
the code i wrote is
loop at li_ekes assigning <fl_ekes>.
read table li_eine assigning <fl_eine> with table key (here i need to give some unique fields to join these two fields please guide me which field i can use.).
<fl_ekes>-ebtyp = <fl_ekes>-EINDT + <fl_eine>-j_3alitra.Hi,
Both tables have field EBELN in common.
You can use it to extract data from both.
Hope this helps.
reward if helpful.
Regards,
Sipra -
Hi all,
In a report program i have used a inner join. I am getting error in the where condition. Here I have furnished part of my code for ur reference.
Tables : mara, makt, mard.
data : begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
lgort like mard-lgort,
labst like mard-labst,
end of itab.
parameters : matnr like mara-matnr.
start-of-selection.
select maramatnr maktmaktx mardlgort mardlabst into corresponding fields of iab from mara inner join maktx on maramatnr = maktmatnr inner join mard on maktmatnr = mardmatnr where matnr eq matnr.
in the where condition I am getting the following error message.
matnr has two meanings in data dictionary.
Please help me in sort out this problem and also tell me more abt inner joins.
thanks.HI,
You can achieve this in two ways:
1st:
into corresponding fields of TABLE itab
2nd:
if you have inner join you don't need where any more at all! you already have connections.
if you still need then use:
tablename~fieldname
for both sides!
if in your example matnr from left side is local or global variable then you have problem with some naming conventions which usually are used in SAP.
try 1st points at the beggining
i'd write your select in this style
Code:
select mara~matnr
makt~maktx
mardlgort mardlabst
into corresponding fields of table itab
from ( mara
inner join makt on maktmatnr = maramatnr
and makt~spras = sy-langu )
inner join mard on mardmatnr = maramatnr.
OR
Code:
select mara~matnr
makt~maktx
mardlgort mardlabst
into corresponding fields of table itab
from ( mara
inner join makt on maktmatnr = maramatnr )
inner join mard on mardmatnr = maramatnr
where
makt~spras = sy-langu.
Cheers,
Chandra Sekhar. -
what is the max no of tables that can be joined in inner joins?
Thanks in advance
srinivas khi,
there is no limit for table number in inner join
just need to follow some rules..
1. You can use cluster table in innner join e.g. BSEG
2. You system performance depends on number of tables..
3. In innner join try to use all primary key fieds in where condition.
have a nice day!
sachin -
Doubt Regarding LEFT JOIN Operation
Hello,
With the Old syntax in place it is easier for find that which join is performed on which table ...
But with the new syntax ..m getting bit confused when INNER & LEFT JOINS used together ...
Below is the FROM clause ...please explain .. how this JOIN is gonna take place ..& which table is Left joined with whom...
FROM VW_TRANS_MANAGER_SALES ref_1
LEFT OUTER JOIN VW_AGREE_ASSIGN_TAG_DTLS ass
ON Trim(ass.agreement_id) = trim(ref_1.AGREEMENT_ID)
LEFT OUTER JOIN VW_CURENT_RATING_DTLS CURR
ON (ref_1.company_code =curr.COMPANYCODE)
LEFT OUTER JOIN VW_PREV_RATING_DETAILS PREV
ON (ref_1.company_code =prev.COMPANYCODE)
LEFT OUTER JOIN CRMADMIN.CO_MA_COMPANY_CONTACTS cont
ON (ref_1.CLIENT_CONTACT_ID= cont.CONTACT_ID)
LEFT OUTER JOIN CRMADMIN.COR_CRM_MST_CITY city
ON (city.City_id= cont.City_id))
---------------------------------------------------------------------------------------------------------------------------------------Hi,
Aijaz Mallick wrote:
Yeah .. but was a bit Confusing as u used 2 columns in each table....
Doesn't it depends on the joining condition we use ... lets Say ..if i use an INNER join after 2 LEFT join ... & m doing an that inner join with the first SOURCE table .... then will it perform a join on the resultset on the previous Joins...???Sorry, I'm not sure what you're asking.
Please post a specific example of a join that you don't understand, or some results that you don't know how to get.
Use commonly available tables (like those in the scott or hr schemas) or post your own CREATE TABLE and INSERT statements.
Using ANSI syntax, the results are as if the joins were done in the order they appear in the FROM clause (even though the optimizer may not actually do them in that order).
For example, in the querry below, the inner-join between emp and salgrade is done first, then the outer join with dept is done to that result set.
SELECT d.dname
, e.ename
, g.losal
FROM scott.emp e
JOIN scott.salgrade g ON e.sal BETWEEN g.losal
AND g.hisal
RIGHT OUTER JOIN scott.dept d ON e.deptno = d.deptno
;Output:
DNAME ENAME LOSAL
ACCOUNTING CLARK 2001
ACCOUNTING MILLER 1201
ACCOUNTING KING 3001
RESEARCH FORD 2001
RESEARCH SCOTT 2001
RESEARCH JONES 2001
RESEARCH ADAMS 700
RESEARCH SMITH 700
SALES BLAKE 2001
SALES ALLEN 1401
SALES MARTIN 1201
SALES WARD 1201
SALES JAMES 700
SALES TURNER 1401
OPERATIONSNotice that the OPERATIONS department, which has no matches in the other tables, is still included because of the outer join.
If you want to have the joins done in a different order, you can explicitly join some table first, either in a sub-query or just by grouping joins within parentheses in the same FROM clause, as in the query below (which produces the same results as the query above):
SELECT d.dname
, e.ename
, g.losal
FROM scott.dept d
LEFT OUTER JOIN ( -- Join the following tables first:
scott.emp e
JOIN scott.salgrade g ON e.sal BETWEEN g.losal
AND g.hisal
) ON d.deptno = e.deptno
;
Maybe you are looking for
-
Can you use apps that are on your phone in Itunes?
My question stems from having to set my Iphone 4 back to stock settings. I do sync with the cloud but for some reason it did not do it correctly. I lost my apps on my phone but still have them all on my Itunes. One app I see on my Itunes that I ne
-
Steps to create service in SICF transaction
hi.. steps to create service in SICF transaction thank you.
-
How do i stream Brawo films to my imac
I have found the following site Brawo.com and it allows me to stream and watch films free of charge on my ipad, this is graet when im out and about but when i tried on my imac at home it doesnt seem to allow me too. I can watch a trailer of some film
-
Database Character Set Conversion from WE8ISO8859P1 to UTF8
Hi All I want to migrate data from one database to another database But my original database character set is WE8ISO8859P1 but i want to migrate it to database which has character set UTF8 because of character set it don't shows me Marathi data which
-
Bankruptcy on my Credit report
I originally filed for Chapter 13 in July 2008. 3 Days Before Thanksgiving of that same year my company downsized and I was laidoff. I was not able to make payments and I eventually defaulted. By January 2009, I refiled my case and paid for another y