3 way table join for a view?
Hi,
I need to create a view comprising several complex queries (at least to me...). Below is an example where I have to do a three way table join, based on multiple columns from each table.
This is the data I need to get at:
table1."DISTRICT TYPE",
table1. "DISTRICT CODE",
table1."EO_NAME"
With the following constraints:
table1 joined with table2 via DISTRICT_TYPE and DISTRICT CODE
table2 joined with table3 via PRECINCT and PRECSUB
What is the best query to use in this situation? Or, is there a better alternative, considering I do have to create a view?
Thanks very much.
This one really is a basic join question, and a quick perusal of the SQL Reference Manual, or any basic SQL book would provide an answer. However ...
Assuming your tables look like:
TABLE1
district_type
district_code
eo_name
TABLE2
district_type
district_code
precinct
precsub
TABLE3
precinct
precsub
other_stuff
then
SELECT a.district_type, a.district_code, a.eo_name,
b.precinct, b.precsub,
c.other_stuff
FROM table1 a, table2 b, table3 c
WHERE a.district_type = b.district_type and
a.district_code = b.district_code and
b.precinct = c.precinct and
b.precsub = c.precsub
Similar Messages
-
Can do explict join for database view?
Hi all,
I would like to ask whether there is a way to specify the join condition to be outer join for database view. It is because I need to map 2 tables in the view and I want to be able to find the record in the view table if the record exists in Table A but not Table B.Hi Jaya,
A Maintenance View helps you to maintain data that is distributed across different or multiple database tables. So, it becomes an easy way to update data and without any programing effort. You can create a Maintenance View across multiple tables with one Table as Primary Table and others as Secondary Tables. But the tables must be related with each other with a Foreign Key Relationship.
Have a look at the following link which tell you about the procedure of creating the Maintenance Views :
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21ed2d446011d189700000e8322d00/frameset.htm
Hope this helps.
Thanks,
Samantak. -
Tables/Joins for logical tables being combined
I have 2 logical tables set up that have multiple physical table sources (using map to these tables). Some of the physical sources are the same in each logical table. It seems that when I make selections from Answers and look at the SQL, it is picking tables from both logical tables (instead of just the one I used). It is also grabbing the content (additional 'where condition') from the other logical table as well. Why is it doing that?
Yes it is kind of limitation in obiee. But there are some solutions which might deviate from best practices.
Sol 1. Snowflake the dimensions in Business Model. Rather than merging both of them into single logical table, separate them into two different logical tables.
Sol 2. For the logical table , have two LTSs. First LTS will have both tables and all columns mapped to both tables. Second LTS will have only main table, Columns belong to that table only mapped. In this way when you selected columns related to first source system will use second LTS which has only only one table.
- Madan Thota -
SUS - Table joins for PO and Invoice
Hello,
I am trying to create a report in SUS and I'd like to join some tables.
I'd like to be able to pull all the SUS PO's and SUS Invoices filtered by Vendor and Date. Looking at BBP_PD all the data is already linked under "Header Links" but I'm not sure how to use those links in a query.
CRMD_ORDERADM_H seems to contain most of the PO and Invoice data I need but how can I connect a PO with the correct invoice?
Thanks,
MattSolution:
Use the following function modules to look up this data.
BBP_PD_SUSPO_GETLIST
BBP_PD_SUSPO_GETDETAIL
This returns a lot of data so you can pick and choose what you need.
Thanks,
Matt -
Re: table joining for k810009
Hi Experts,
I am developing a new report by taking output field from table k810009 and some selection screen field from mara.
Below is my code
TABLES : MARA,K810009.
TYPES: BEGIN OF TY_FINAL,
ARTNR TYPE K810009-ARTNR, " MATERIAL NUMBER
PAPH1 TYPE K810009-PAPH1, " PRODUCT HIERARCHY LEVEL 1
PAPH2 TYPE K810009-PAPH2, " PRODUCT HIERARCHY LEVEL 2
PAPH3 TYPE K810009-PAPH3, " PRODUCT HIERARCHY LEVEL 3
PAPH4 TYPE K810009-PAPH4, " PRODUCT HIERARCHY LEVEL 4
PAPH5 TYPE K810009-PAPH5, " PRODUCT HIERARCHY LEVEL 5
PAPH6 TYPE K810009-PAPH6, " PRODUCT HIERARCHY LEVEL 6
WWREP TYPE K810009-WWREP, " REPRESENTATIVE MATERIAL FOR PCA
BUKRS TYPE K810009-BUKRS, " COMPANY CODE
PRCTR TYPE K810009-PRCTR, "PROFIT CENTER
VKORG TYPE K810009-VKORG, " SALES ORGANISATION
WERKS TYPE K810009-WERKS, "PLANT
MAKTX TYPE MAKT-MAKTX, " MATERIAL DESCRIPTION
END OF TY_FINAL.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_MTART FOR MARA-MTART. "MATERIAL TYPE
S_MATKL FOR MARA_MATKL. " MATERIAL GROUP
S_ARTWR FOR K810009-ARTWR. "MATERIAL NUMBER
S_WERKS FOR K810009-WERKS. "PLANT
S_BUKRS FOR K810009-BUKRS. "COMPANY CODE
S_VKORG FOR K810009-VKORG. "SALES ORGNISATION.
SELECTION-SCREEN END OF BLOCK B1.
can any one throw some light how to dispaly output filed based on my selection screen.
Regards,
Am
Moderator Message: Just do not post your requirement. First try out on your own & get back to the forums in case of
any specific problem.
Edited by: Suhas Saha on Jan 15, 2012 2:49 PMHi Soumya,
Based on my selection screen i.e mara table can we proceed to Ktable.
i have written the code upto here
type-pools: slis.
TABLES : MARA,K810009.
TYPES: BEGIN OF TY_FINAL,
ARTNR TYPE K810009-ARTNR, " MATERIAL NUMBER
PAPH1 TYPE K810009-PAPH1, " PRODUCT HIERARCHY LEVEL 1
PAPH2 TYPE K810009-PAPH2, " PRODUCT HIERARCHY LEVEL 2
PAPH3 TYPE K810009-PAPH3, " PRODUCT HIERARCHY LEVEL 3
PAPH4 TYPE K810009-PAPH4, " PRODUCT HIERARCHY LEVEL 4
PAPH5 TYPE K810009-PAPH5, " PRODUCT HIERARCHY LEVEL 5
WWREP TYPE K810009-WWREP, " REPRESENTATIVE MATERIAL FOR PCA
BUKRS TYPE K810009-BUKRS, " COMPANY CODE
PRCTR TYPE K810009-PRCTR, "PROFIT CENTER
VKORG TYPE K810009-VKORG, " SALES ORGANISATION
WERKS TYPE K810009-WERKS, "PLANT
MAKTX TYPE MAKT-MAKTX, " MATERIAL DESCRIPTION
MATKL TYPE MARA-MATKL, "MATERIAL GROUP
END OF TY_FINAL.
DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL.
DATA: WA_FINAL TYPE TY_FINAL.
data: it_fcat type slis_t_fieldcat_alv.
data: wa_fcat type slis_fieldcat_alv.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_MTART FOR MARA-MTART, "MATERIAL TYPE
S_MATKL FOR MARA-MATKL, " MATERIAL GROUP
S_ARTNR FOR K810009-ARTNR, "MATERIAL NUMBER
S_WERKS FOR K810009-WERKS, "PLANT
S_BUKRS FOR K810009-BUKRS, "COMPANY CODE
S_VKORG FOR K810009-VKORG. "SALES ORGNISATION.
SELECTION-SCREEN END OF BLOCK B1.
select artnr
paph1
paph2
paph3
paph4
paph5
wwrep
bukrs
prctr
vkorg
werks from k810009 into table it_final
where artNr in s_artNr
and werks in s_werks
and bukrs in s_bukrs
and vkorg in S_vkorg.
Please can u proceed from here how to get that output.
Regards,
Am -
SQL Query with 3 tables to create a view
Hi
I have got an existing view "View_output" formed with a query which works fine:
select A,B,C,D,E,F,G,H from GTS1 where D is not null
UNION
select A,B,C,D,E,F,G,H from GTSN1 where D is not null;It works fine, in the output I have columns A,B,C,D,E,F,G,H
New requirement : Modify the view, by adding a new column 'I' so that the view should have
columns A through I, and no column values should be null.
This column "I" is coming from a table, say DLC
Data in DLC is a subset of the original view "View_output"and DLC have the foll.columns:
("View_output" is a datablock source for a form and only selected column values are put as output in DLC
after form manipulation)
DLC is having only 5 columns -B,C,F,H,I
When I give:
(select A,B,C,D,E,F,G,H,NULLfrom GTS1 where D is not null
UNION
select A,B,C,D,E,F,G,H,NULL from GTSN1 where D is not null)
UNION
select NULL,B,C,NULL,NULL,F,NULL,H,I
from
DLC where I IS NOT NULL;It UNIONS all required rows in the 3 tables but columns A,D,E,G are NULL, but how can I get
data in these columns?
Edited by: Krithi on 30-Oct-2009 05:43
Edited by: Krithi on 30-Oct-2009 08:13Hi arun thats not the real isue..
I have corrected the second code now, it was a typo from my side..
all three tables already have 9 columns selected..
The view created from GTS1 and GTSN1 is constantly changing
There is no way to add column 'I' to any of these above tables
The view is the input to a form..User ticks a tickbox corresponding to records needed by them (These are the columns in the original view mentioned above)..and based on certain logic,only selected columns are now inserted/updated into the output table through the form..this is the table DLC
Now they want to insert a new data(free text) through the form, this field correspond to each record in the form ;this is supposed to be column 'I'(not designed yet)..
this is not there in the original input tables selected for the view...But then I added this column to the output table DLC (Cant think of any other method) so that column I can also get combined in the view.
Now what I want is recreate the view through,
create or replace view statement.
the view should effectively pull data from 3 tables .
The relation between 3 tables :
DLC is a subset of GTS1 and GTSN1
but may also contain data which is not in union of GTS1 and GTSN1
Only field I need from DLC is field 'I', and that too if the data is there in the union of GTS1 and GTSN1 -
Table Join brings in multiple records
Hi guys,
I have created a table join for 2 HR master tables to get a view.
When i output the view however it brings in multiple records for each employee.
I have set PERNR as the Key field to join the tables but instead of giving me one instance of employee it picks it up 2 records....and in some cases many more, is their a fix for this?
ThanksHi,
Try using a combined primary key;
PERNR, BEGDA and ENDDA
There are more primary keys to be combined but try with this 3.
~BiSu -
Reg: Join Conditions for Tables to create a View for Generic Extraction
Hi Experts,
Am trying to extract the data from Solman, for this purpose am creating a Generic Extractor based on three tables. So, can anyone please help me out by providing the join conditions to create a view based upon the following three tables,
1. CRM_ORDERM_H
2. DNOD_NOTIF
3. DNOD_NOTIF_S
Anyways i require the following fields in the extractor finally:
CRM CHANGED AT
GUID
SAP COMPONENT
RELEASE
REPORTED BY
These are the some of the major fields that i require in the final extractior. Please help me out ASAP with the table join conditions..
Will Assign Points for the helpfull answer...
Thanks,
Gattu.Hi,
I don't know the table CRM_ORDERM_H however you can link DNOD_NOTIF and DNOD_NOTIF_S
DNOD_NOTIF_S-CLIENT = DNOD_NOTIF-CLIENT
DNOD_NOTIF_S-GUIDS = DNOD_NOTIF-GUIDS
For the third table could you please paste here its definition like the hereunder?
Transp. table DNOD_NOTIF Active
Short Text Notification Header
Field KeyInitData element Data TyLengthDecimaShort Text
CLIENT X X MANDT CLNT 3 0Client
GUIDH X X DNOT_GUIDH RAW 16 0GUID Notification
.INCLUDE DNOS_NOTIF_INT STRU 0 0Notifications (Header, Internal Fields)
OBJNR DNOT_OBJNR CHAR 22 0Status Management Object Number
STATUS DNOT_STATUS CHAR 1 0Notification Status
DELETED DNOT_DELE_N CHAR 1 0Deletion Indicator Notification
PROCESSOR DNOT_PROC CHAR 12 0Current Processor
TYPE_PROC DNOT_TYPE_PRC CHAR 2 0Type of Processor
REPORTER DNOT_REPORTER CHAR 12 0Reported By
TYPE_REPO DNOT_TYPE_REP CHAR 2 0Type of Notification Creator
CREA_TSTMP DNOT_CREA_TSTMP DEC 15 0Entry Time Stamp
CHNG_TSTMP DNOT_CHNG_TSTMP DEC 15 0Time of Last Change
START_TSTMP DNOT_START_TSTMPDEC 15 0Initial Response Time - Time Stamp
END_TSTMP DNOT_END_TSTMP DEC 15 0Requested End of Processing - Time Stamp
CLO_TSTMP DNOT_CLO_TSTMP DEC 15 0Completion Time Stamp
.INCLUDE DNOS_NOTIF_EXT STRU 0 0Notifications (Header, External Fields)
NUMB DNOT_NUM CHAR 12 0Notification Number (External)
REFNUM DNOT_REFNUM CHAR 20 0External Reference Number
TYPE_NOTIF DNOT_TYPE_N CHAR 6 0Message category
CATEGORY DNOT_CATEGORY CHAR 12 0Topic, Area
SUBJECT DNOT_SUBJECT CHAR 60 0Re:
PRIORITY DNOT_PRIORITY CHAR 1 0Notification priority
LANGUAGE DNOT_LANG_N LANG 1 0Notification Language
hope this helps...
Olivier. -
What is the best way to replace the Inline Views for better performance ?
Hi,
I am using Oracle 9i ,
What is the best way to replace the Inline Views for better performance. I see there are lot of performance lacking with Inline views in my queries.
Please suggest.
RajWITH plus /*+ MATERIALIZE */ hint can do good to you.
see below the test case.
SQL> create table hx_my_tbl as select level id, 'karthick' name from dual connect by level <= 5
2 /
Table created.
SQL> insert into hx_my_tbl select level id, 'vimal' name from dual connect by level <= 5
2 /
5 rows created.
SQL> create index hx_my_tbl_idx on hx_my_tbl(id)
2 /
Index created.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(user,'hx_my_tbl',cascade=>true)
PL/SQL procedure successfully completed.
Now this a normal inline view
SQL> select a.id, b.id, a.name, b.name
2 from (select id, name from hx_my_tbl where id = 1) a,
3 (select id, name from hx_my_tbl where id = 1) b
4 where a.id = b.id
5 and a.name <> b.name
6 /
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=2 Bytes=48)
1 0 HASH JOIN (Cost=7 Card=2 Bytes=48)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
3 2 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
4 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
5 4 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
Now i use the with with the materialize hint
SQL> with my_view as (select /*+ MATERIALIZE */ id, name from hx_my_tbl where id = 1)
2 select a.id, b.id, a.name, b.name
3 from my_view a,
4 my_view b
5 where a.id = b.id
6 and a.name <> b.name
7 /
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=1 Bytes=46)
1 0 TEMP TABLE TRANSFORMATION
2 1 LOAD AS SELECT
3 2 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
4 3 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
5 1 HASH JOIN (Cost=5 Card=1 Bytes=46)
6 5 VIEW (Cost=2 Card=2 Bytes=46)
7 6 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
8 5 VIEW (Cost=2 Card=2 Bytes=46)
9 8 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
here you can see the table is accessed only once then only the result set generated by the WITH is accessed.
Thanks,
Karthick. -
I am beginner in MVC and I would like to create a view which populates two (or more) joined tables in a single view table as described below.
I have two tables:
1 - Bloggers: - bloggerID (int);
- bloggerName (string)
2 - Blogs: - blogID (int);
bloggerID (int);
- blogTitle (string);
- blogImage (string)
A blogger can have one or more blogs while one blog must be related to only one blogger.
I would like to have a view table on my webpage as the following:
Blogger Name
Blog Title
Blog Image
Noris Gang
Virus
virus.jpg
Noris Gang
Desktops
desktop.jpg
Gauthier
Books
books.png
John Leon
NNNMHJhjdhj
Nmbj.jpg
I'm using MVC 4 (or at least 3).
Thanks for your help.Hello,
From your description, it is not very clear that what you mean about the View, if it means the View concept in database as SQL Server, your required view should be as below:
Create view
as
Select Bloggers.bloggerName, Bloggers.blogTitle, Bloggers.blogImage
From Bloggers join Blogs on Bloggers.bloggerID = Blogs. bloggerID
If it means the UI view in MVC concept, I suggest you could ask it on the MVC forum:
http://forums.asp.net/1146.aspx
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Materialized View with Join for FAST Refresh
Hi Gurus,
Facing issues in MV with a simple join for FAST Refresh.
2 sample Tables:
1. employee
empid integer PK
empname varchar(50)
deptid integer FK
2. delta_employee
empid integer PK
empname varchar(50)
deptid integer FK
dmlflag varchar(2)
watermark integer
Code is as given below -
CREATE MATERIALIZED VIEW LOG ON work.employee
WITH SEQUENCE,rowid(empid)
INCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW LOG ON work.delta_employee
WITH SEQUENCE,rowid(empid)
INCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW work.MVEmployee REFRESH force on
demand with rowid AS
select e.empid,e.empname,e.deptid,d.empid t1
from work.employee e, work.delta_employee d
where e.empid = d.empid;
Able to perform Complete Refresh. Not able to use Fast Refresh for
incremental refresh.
Please help.
Thanks,
J KumarFound a solution,
As per oracle documentation rowid fileds should be included in the Select statement. Even though I included the rowid fields, empid in this case it still didnt work.
The implementation of the rowid column should be included with tablename.rowid instead of the tablename.columnname !
Modified script is as given below.
CREATE MATERIALIZED VIEW WORK.MVEMPLOYEE
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
AS
select e.rowid "empid",d.rowid "t1" ,e.empname,e.deptid
from work.employee e, work.delta_employee d
where e.empid = d.empid;
And It really WORKS -
Can we write a join on a view and a table
Hi all,
can we write a join on a view and a table. i got the requirement from my functional people about the following one
Select CAUFV-AFUNR, CAUFV-AUART, AFVC-VORNR, CAUFV-FTRMI, CRHD-ARBPL
into <ProOrd>, <OrdTyp>, <Opt>, <RelDat>, <WorCen>
from CAUFV, AFVC, CRHD
where CAUFV-WERKS = plant in selection screen
and CAUFV-AFUNR = production order in selection screen
and CAUFV-AUART = production order type in selection screen
and CAUFV-FTRMI = range of release date in selection screen
and CAUFV-AUFPL = AFVC-AUFPL
and AFVC-ARBID = CRHD-OBJID
and CRHD-OBJTY = A
here CAUFV is a view and CRHD and AFVC are transperent tables.
please tell me any feasible solution for this..
Thanks in Advance..Hi
Refer these links:
<u>http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec84446011d189700000e8322d00/content.htm</u>
<u>http://www.sap-img.com/abap/what-is-the-different-types-and-usage-of-views.htm</u>
<u>http://www.karakas-online.de/forum/viewtopic.php?t=730</u>
Thanks
Vasudha
Message was edited by:
Vasudha L -
Strange behaviour of view based on several tables join with union all
Dear fellows we r facing a strange problem we have a view based on several tables joined by union all ,when we issue an ordered query on date,rows returned are unusually different than they should be .
Is oracle has some special behaviour for view based on union all ?
I m using oracle 8.1.6 on windows 2000
Kashif SohailDid you ever solve this problem? I have two select statements based on 4 tables and 3 views using about 5 more tables. When I execute each select individually I get exactly what is expected. When I UNION ALL both selects together, I get "no rows returned", however when I UNION them I get exactly what is expected. I should get the same answer for both UNION ALL and UNION. The two select statements are identical, except for one column where I changed the constant to be different. Any thoughts?
-
How to insert a record for tables joined
Hi,
first of all I've been learning Forms for few days.
I've created a simple form where I report the columns from two tables joining them.
Once I've entered a new list of values in the fields of the form, how can I insert them in the two tables? What I've done, but it doesn't work, is to set "Insert Procedure Name" of the data block = to my procedure compiled in "Program Units" hoping that once pushed the "Execute Query" button in the running form worked, but it didn't work.
Any advice for the better way to how execute an insert in one or more tables with the content of the fields of the form?
My versions are: database 10gXE and forms 10.1.2.0.2
Thanks in advance!Hi,
Create two data blocks using create data block wizard and join it with a relation. Display the fields you want and form will automatically save your updates in the both tables.
When there is a join you can not update all the fields.
Regards
Yoonas
Edited by: yoonus on Oct 3, 2012 1:04 AM -
Hi,
Could you provide joins for below tables:
mtl_system_items_b
mtl_kanban_cards
mtl_onhand_quantities_detail
MTL_SECONDARY_INVENTORIES
MTL_ITEM_CATEGORIES
MTL_CATEGORY_SETS_TL
MTL_CATEGORIES_B
ThanksYes it is kind of limitation in obiee. But there are some solutions which might deviate from best practices.
Sol 1. Snowflake the dimensions in Business Model. Rather than merging both of them into single logical table, separate them into two different logical tables.
Sol 2. For the logical table , have two LTSs. First LTS will have both tables and all columns mapped to both tables. Second LTS will have only main table, Columns belong to that table only mapped. In this way when you selected columns related to first source system will use second LTS which has only only one table.
- Madan Thota
Maybe you are looking for
-
How to make New Events appear at TOP of page, not Bottom?
When I import photos, they are automatically put into a new Event. That's great. But that Event appears way at the bottom of my long events list, even though my Events are shown chronologically with the most recent events right at the top. I have to
-
I recently bought a bunch of music apps. I jet updated to OS 7.12. They are available to re download from the app store, but not on the main iPad desktop as before. Is there a way to stop this happening again? Thanks
-
What do I have to do to my Apple Extreme to switch it from a DSL broadband modem to a cable modem?
-
Business Objects Mobile (V 11.5.0) - Issues
Hi, I saw one issue in this version of BO Mobi. The Call Link works fine in windows mobile but the SMS Link fails and gives an error on windows mobile device. I first tried the BO Mobi Demo from the Business Objects Website and worked fine. Now when
-
Hi all, First time posting on here. Have had a look through various threads and can't find a similar one. I have an N97 (Vodafone, Ireland, FW 21.0.045) and like many people am driven mad by the GPS. It's the usual problems - phone takes ages to get