Retriving data by joining several tables and total general
Hello PL/SQL gurus and experts.I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
I have table-
I have the following three tables
DROP TABLE Person_Tb;
create table Person_Tb(Person_ID,Person_FName,Person_LName) as select
1001, 'Nikki','Carlos' from dual union all select
1002, 'Nina', 'Harrison' from DUAL union all select
1003, 'Mike', 'Carwely' from dual union all select
1004, 'Michael', 'Robinson' from DUAL union all select
1005, 'Hendi', 'Klum' from dual union all select
1006, 'Robert', 'Regan' from dual union all select
1007, 'Maria', 'Washington' from dual union all select
1008, 'Kistrien', 'Obama' from dual union all select
1009, 'Andrew', 'Regan' from dual union all select
1010, 'Emma', 'Thomsan' from dual union all select
1011, 'Andy', 'Grant' from dual union all select
1012, 'Brandy', 'Decosta' from dual;
DROP TABLE Teacher;
create table Teacher(Teacher_ID,Fee_Date,Account_ID) as select
1001, '04/04/2013',3004 from dual union all select
1002, '04/06/2013',3006 from DUAL union all select
1003, '04/08/2013',3014 from dual union all select
1004, '04/08/2013',3017 from DUAL union all select
1005, '04/09/2013',3019 from dual union all select
1011, '04/12/2013',3025 from dual union all select
1012, '04/12/2013',3046 from DUAL;
DROP TABLE Student;
create table Student(Student_ID,Subaccount_ID) as select
1006,3004 from dual union all select
1007,3006 from DUAL union all select
1008,3004 from dual union all select
1009,3017 from DUAL union all select
1010,3017 from dual;
I am able to recover the data individually Tracher and student as -.Select distinct pt.Person_LName || ',' ||
pt.Person_FName Trdr_NM
from Student st, person_Tb pt
where st.Student_id = pt.PERSON_ID
Select distinct pt.Person_LName || ',' ||
pt.Person_FName SubAct_Invst
from Teacher tc, person_Tb pt
where tc.teacher_id = pt.PERSON_ID
I need to get the records for all teachers who are associated with students-SubAct_Invst Trdr_NM
----------------------------------------------------
Carlos,Nikki
Regan,Robert
Obama,Kistrien
Harrison,Nina
Washington,Maria
Carwely,Mike
Robinson,Michael
Regan,Andrew
Thomsan,Emma
Klum,Hendi
Grant,Andy
Decosta,Brandy
------------------------------------------------------
Grand Total
7 5
But how to retrieve the data above format, many want to help. Thanks in advance and I really appericate your time and efforts.
Ideally, your condition must be handled by a front-end tool...
If you need specifically using SQL, you can check my previous post...
Tags: Database
Similar Questions
-
Hello
We are working on a data warehousing project and wonder how do to join several tables that each are versioned separately (type SCD 2 with a valid and valid to date).
Because for example, we get our client from a single source of information (id customer, name, etc.) and the information on the rate of customer from another source. The sources are different, we have the separate tables for them and each of them gets versioned independently.
Here's my customer table (with its own valid and valuable to the columns).
ID Name of the customer Valid from Valid until the 1 CitiBank 1 JANUARY 14 JANUARY 1, 15 1 New CitiBank 2 JANUARY 15 FEBRUARY 1, 15 1 Latest CitiBank 2 FEBRUARY 15 APRIL 1, 15 And similarly the Client side ID and rating information.
ID Note Valid from Valid until the 1 Platinum 1 JANUARY 14 FEBRUARY 1, 14 1 Premium FEBRUARY 1, 14 1ST MARCH 15 I want to merge the two tables above and present information at a glance. I have some difficulty to determine validates the valid columns.
ID Name of the customer Note Valid from (Calculated) Valid until the (calculated) 1 CitiBank Platinum 1 JANUARY 14 FEBRUARY 1, 14 1 CitiBank Premium FEBRUARY 1, 14 JANUARY 1, 15 1 New CitiBank Premium 2 JANUARY 15 FEBRUARY 1, 15 1 Latest CitiBank Premium 2 FEBRUARY 15 1ST MARCH 15 And it's the query I used to get the above result:
SELECT client. id ,
customer . name ,
CRM . level ,
Greatest (client. vld_fm , crm. vld_fm ),
Least (client. vld_to , crm. vld_to )
DE client client,
client_rating crm
OÙ client. id = crm. id
AND ( client. vld_fm <= crm. vld_fm
AND client. vld_fm <= crm. vld_to
AND client. vld_fm >= crm. vld_fm
AND client. vld_fm >= crm. vld_to )
OR ( client. vld_fm BETWEEN crm. vld_fm AND crm. vld_to )
OR ( client. vld_to BETWEEN crm. vld_fm AND crm. vld_to );
The problem is we have several data sources (and each with its own versions) and joins become so very very complex. Is there a better way to write the query?Or maybe a better way to design our tables?
Thanks for your help.
Anand
Hello
you only need ranges that overlap to join.
Re: How do to sql query in a loop
Is a simpler way to test if the x_start to x_stop range comes into conflict with the range of y_start to y_stop
WHERE x_start <= y_stop AND y_start <= x_stop
In other words, two overlapping if and only if everyone will start before the other ends one. If this is not obvious (and it was certainly not clear to me when I heard it), then look at it this way: two ranges are not overlapping if and only if one of them starts after the end of the other.
Concerning
Marcus
-
joining several tables to generate data
with itemlist as
(select 1 cid, listname 'test', 'r' flg Union double all the)
Select 2 cid, listname 'test2', ' not flg double
),
category 1)
Select 1 cid, 122 k' sub '123' catcode, of any double Union
Select 1 cid, '234i' catcode, sub '124' all Union double
Select 1 cid, 238 k' void '124' catcode, double
)
void)
Select 1 cid, sub '123' of any union double
Select 1 cid, sub ' 124' double
)
I want to write a static query that gathers all the tables and produces the following output assuming that
CID is you pass as a parameter
CID listname flg topic catcode
1 123 122 k r test
1 test of r 234i 124
1 124 238 k r test
Suppose the data as changes to follow and even cid 1 is to pass as a parameter:
with itemlist as
(select 1 cid, listname 'test', 'r' flg Union double all the)
Select 2 cid, listname 'test2', ' not flg double
),
category 1)
Select 1 cid, 122 k' sub '123' catcode, of any double Union
Select 1 cid, '234i' catcode, sub '124' all Union double
Select 1 cid, 238 k' void '124' catcode, double
)
void)
Select 2 cid, sub '123' of any union double
Select 2 cid, sub '124' double
)
then the output should be
CID listname flg topic catcode
1 r test 123
1 test of r 124
1 test of r 124
for a final example, suppose the data now as to user 1 as cid
with itemlist as
(select 1 cid, listname 'test', 'r' flg Union double all the)
Select 2 cid, listname 'test2', ' not flg double
),
category 1)
Select 2 cid, 122 k' sub '123' catcode, of any double Union
Select 2 cid, catcode '234i', '124' void in any union double
Select 2 cid, 238 k' void '124' catcode, double
)
void)
Select 1 cid, sub '123' of any union double
Select 2 cid, sub '124' double
)
output must be
CID listname flg topic catcode
1 test r 123
Basically, the user will pass a cid, in this case 1. I'll read the itemlist where cid = 1 and I want to join all the other tables
to itemlist in such a way that I can generate extra lines. If no entry is found for cid 1, for example, in category 1 or auxiliary table
then the beloging column of this table must be null in the result
can someone help me write a query to produce the output above
Hello
elmasduro wrote:
...
Here is an explanation of the output. a user will have a front screen where it can enter itemlist info.
then in a submenu may enter a category or sub or both or none of them. the user can select multiple categories or sub
When the user presses the button Save, an entry will be made in the itemlist table, for example the cid = 1.
If he choose a category but without Subs, then will be entered into the table at say cid = 1
but no entries will be made for sub because he chose not to all values. If he chooses void instead of category values
then sub taable will fill and category is not. If he chooses the category and under, then both will be filled.what I want to do is to join the itemlist with table category and sub table and get the data to the Scriptures, this intervention of the user.
These entries not found will be the null value column in the result.
for example, the cid = 1 itemlist, if user enter category but not void, itemlist will be the join with the table category and sub
but since sub has no entry for the cid = 1, the column object will be empty in the output, but catcode will fillI'm so confused.
It is a query (that is, just a SELECT statement, which shows the data already present in the tables), or is this a DML statement, that will add data to the tables? If it's just a query, then do not say things like "entries will be taken" or "filled with tables.
Assuming you want a request maybe you want something like this:
WITH c_and_s AS
(
SELECT NVL (c.cid, s.cid) AS cid
NVL (c.sub, s.sub) AS topic
, NVL2 (s.cid, c.catcode, NULL) AS catcode
CATEGORY 1 c
FULL OUTER JOIN void s ON c.cid = s.cid
AND c.sub = s.sub
)
SELECT i.cid, i.listname, i.flg
cs.subject, cs.catcode
Itemlist I have
LEFT OUTER JOIN c_and_s ON cs.cid = i.cid cs
WHERE the i.cid (1) - you can do the cids 2 or several at the same time, if you want to
ORDER BY i.cid, cs.subject, cs.catcode
;
This example gets the output you asked data sample you posted.
-
Outer Join and joining several Tables
Hello
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below
How can I select all the values in table AddProject?CREATE TABLE "ADDPROJECT" ( "VERSIONNO" NUMBER(*,0), "PROJID" VARCHAR2(20), "PROJNAME" VARCHAR2(60), "PROJSTARTDATE" DATE, "PROJSTATUS" VARCHAR2(20), "PROJENDDATE" DATE, "PROJENDTYPE" VARCHAR2(20), "PROJENDREASON" VARCHAR2(1000), "UCPROJECTMANAGER" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, "SRCHFIELD" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "PARENTPROJID" VARCHAR2(20), "PROJHIDDENDATE" VARCHAR2(20), CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE ) CREATE TABLE "ADDASSOCIATE" ( "VERSIONNO" NUMBER(*,0), "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, "CTOJOINDATE" DATE, "STATUS" VARCHAR2(20), "ENDDATE" DATE, "SRCHFIELD" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE ) CREATE TABLE "ASSOCIATEPROJECTLEAD" ( "VERSIONNO" NUMBER(*,0), "PROJLEADASSOID" NUMBER(9,0), "PROJID" VARCHAR2(20), "ASSOCIATEID" NUMBER(9,0), "PROJLEADSTARTDATE" DATE, "STATUS" VARCHAR2(20), "ASSOCPROJHIDDENDATE" VARCHAR2(20), "PROJHIDDENDATE" VARCHAR2(20), "ENDDATE" DATE, CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE ) elect ap.projid,apl.associateid from addproject ap, associateprojectlead apl where ap.projid = apl.projid(+) and ap.projhiddendate = apl.projhiddendate(+) PROJID ASSOCIATEID Proj08 75825 Proj09 75825 Proj10 75825 Proj11 75825 Proj12 259811 Proj01 103035 Proj02 103035 Proj03 320092 Proj04 320092 Proj05 120974 Proj06 367393 Proj07 117618 Proj07 224882 Proj07 246652 prj001 - prj001 - 16 rows returned in 0.00 seconds select ap.projid,apl.associateid,aa.associatename from addproject ap, associateprojectlead apl,addassociate aa where ap.projid = apl.projid(+) and ap.projhiddendate = apl.projhiddendate(+) and apl.associateid = aa.associateid PROJID ASSOCIATEID ASSOCIATENAME Proj11 75825 Amarendra Kumar Singh Proj10 75825 Amarendra Kumar Singh Proj09 75825 Amarendra Kumar Singh Proj08 75825 Amarendra Kumar Singh Proj02 103035 Rajesh Jayaprakash Proj01 103035 Rajesh Jayaprakash Proj07 117618 Chetan Malhotra Proj05 120974 Perumal Rajaram Proj07 224882 Dilshad Ahmad Proj07 246652 Shankar Kausley Proj12 259811 Arunchandar Arun Vasan Proj04 320092 Venkatesh Sarangan Proj03 320092 Venkatesh Sarangan Proj06 367393 Venkata Ramakrishna P 14 rows returned in 0.00 seconds
Published by: Pramukh on August 23, 2012 12:18Hello
I could get the result with a bit of modification
select ap.projid, apl.associateid, aa.associatename from addproject ap left outer join associateprojectlead apl on ap.projid = apl.projid and ap.projhiddendate = apl.projhiddendate left outer join addassociate aa on apl.associateid = aa.associateid
As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.
select ap.projid, apl.associateid, aa.associatename from addproject ap left outer join associateprojectlead apl on ap.projid = apl.projid and ap.projhiddendate = apl.projhiddendate and ap.projID = 'Proj08' left outer join addassociate aa on apl.associateid = aa.associateid ORDER BY ap.projID PROJID ASSOCIATEID ASSOCIATENAME Proj01 - - Proj02 - - Proj03 - - Proj04 - - Proj05 - - Proj06 - - Proj07 - - Proj08 75825 Amarendra Kumar Singh Proj09 - - Proj10 - - Proj11 - - Proj12 - - prj001 - - prj001 - -
-
WITH or CONNECT BY on several tables and function call
Hi all
I saw several post, documentation and several tutorials and cant' wrap your head around the query. I am creating a hierarchy of hosts in a model parent child and for each parent, I need to generate html code. I now have the id of the top most parent but has difficulty to get the logic to generate the output I need.
In short, I have 1 parent with children and some of these children may be parents themselves and the parent over the top of the PAGE is always-1
I need to call the pl/sql function to generate the code (only and only if it is a parent)
I've been at this for awhile and only have the basics but are struggling to try to get what I need. I'im so confused at this point I don't know even how to explain it.
So bear with me, I have included the test data for all who can help:
-STEP 1-> OK
-STEP 2-> DON'T know what I'm doing, but I'm generating an output of hierarchy
-STEP 3-> paths are a bit inaccurate. DB1 and DB2 are repeated and their correct path is/LOCALHOST/RT1/SVR-DEV-01/DB1
-STEP 4-> I'm so confused, I could not explain other then I have to call my function in reverse order of STEP2 so that more "host_object" really is a child and therefore function should not be called.
-- Heis my query my base query SELECT DISTINCT h.id, h.host_object_id, h.display_name, COALESCE(h3.host_object_id, -1) AS parent_id, FROM hosts h LEFT JOIN host_parenthosts h4 ON (h.id = h4.host_id) LEFT JOIN hosts h3 ON h3.host_object_id = h4.parent_host_object_id;
-
Update statement with joins of tables and where Clause
Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.
Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.
The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!
1:
Update PenaltyAll
Set a.indicator = month (b.)
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20
2:
Update PenaltyAll
adjustment indicator =
(select to_char (b., 'MM')
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
"where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
(et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
and b.apr < 20)
Published by: sqlrookie on August 21, 2009 07:04I edited my post, that was my mistake, ANC you try now?
-
How to get data from a database table and insert into a file
Hello
I'm new to soa, I want to create an xml with the data from database tables, I'll have the xsd please suggest me how to get the data in the tables and insert in a file
concerningin your bpel process, you can use the db adapter to communicate with the database.
with this type of adapter, you can use stored procedures, selects, etc to get the data from your database into your bpel workflow.When did it call in your bpel to the db adapter process it will return an output_variable with the contents of your table data, represented in a style of xml form.
After that, you can use the second card (a file synchronization adapter) to write to the content of this variable in output to the file system
-
Feature: How to get subtotals and total general whole?
I am wrtiting a report using SQL and SQL * more to get subtotals and a total general. The COMPUTE function allows me to CALCULATE SUM on a group, but it only gives me subtotals. I am interested in getting a report with subtotals and a final OVERALL TOTAL. Is this possible using SQL * more?
Here is my current code that gives me subtotals:
Here is the code for a grand total:COMPUTE SUM LABEL subtotal OF sal ON deptno SELECT ename, sal, deptno FROM emp ORDER BY deptno; ENAME SAL DEPTNO ---------- ---------- ---------- CLARK 2450 10 VOLLMAN 5000 MILLER 1300 ---------- ********** 8750 subtotal SMITH 800 20 ADAMS 1100 FORD 3000 SCOTT 3000 JONES 2975 ---------- ********** 10875 subtotal ALLEN 1600 30 BLAKE 2850 MARTIN 1250 JAMES 950 TURNER 1500 WARD 1250 ---------- ********** 9400 subtotal
How can I combine the two on a single report?Column DUMMY NOPRINT COMPUTE SUM OF sal ON DUMMY BREAK ON DUMMY SELECT NULL DUMMY, ename, sal, deptno FROM emp ORDER BY deptno; ENAME SAL DEPTNO ---------- ---------- ---------- CLARK 2450 10 VOLLMAN 5000 10 MILLER 1300 10 SMITH 800 20 ADAMS 1100 20 FORD 3000 20 SCOTT 3000 20 JONES 2975 20 ALLEN 1600 30 BLAKE 2850 30 MARTIN 1250 30 JAMES 950 30 TURNER 1500 30 WARD 1250 30 ---------- 29025
Hello
If you want to do with the SQL * Plus COMPUTE command, just give another CALCULATION order "CARRY ON".
Add 'REPORT ON' to the PAUSE command, also.BREAK ON deptno ON REPORT COMPUTE SUM LABEL subtotal OF sal ON deptno COMPUTE SUM LABEL grandtotal OF sal ON REPORT SELECT ename, sal, deptno FROM scott.emp ORDER BY deptno;
Output:
ENAME SAL DEPTNO ---------- ---------- ---------- CLARK 2450 10 KING 5000 MILLER 1300 ---------- ********** 8750 subtotal JONES 2975 20 FORD 3000 ADAMS 1100 SMITH 800 SCOTT 3000 ---------- ********** 10875 subtotal WARD 1250 30 TURNER 1500 ALLEN 1600 JAMES 950 BLAKE 2850 MARTIN 1250 ---------- ********** 9400 subtotal ---------- grandtotal 29025 14 rows selected.
-
How to join several tables source and do the research?
I have a requirement to load a target table by joining 4 source tables. Also, I do a search on a field of table to transform codes and check for NULL values. What will be the best approach for load table target?
Is it possible to do it in a single interface, or do I need to create multiple interfaces to achieve this?
My basic source and target are oracle, and I am planing to use incremental update Oracle merge.
Thank youYou are in the right direction by creating an interface for this transformation.
You will need to drag the source drop 4 tables + the lookup table in the Sources of Interface window and then make the appropriate joins.
Also, look for NULL values in the transformation. Depends on what you want to do with NULL values. If you want to ignore, use a filter.
If you want to make mistakes, use a constraint.
If you want to convert them, use NVLStart with Oracle Update incremental and once successful, use incremental update Oracle MERGE.
-
Summary
two tables:
Table 1 categories
Table 2A categories that someone has selected
HTML form that updates the user's data:
form should show all the options in the category dynamically in table 1
and also to display the check box of the category as controlled dynamically if the person chose by table 2
The nuts and bolts
Attempt 1
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
THE CAT of categories, members_categories mcat
WHERE mcat.member_id = ' "." $_GET ['id']. »"
ORDER BY category ASC
(run on its own, all categories of table 1 are shown twice and the results of table 2 is a total cluster.)
area of the form with checkboxes:
<? PHP {? >}
< input <? PHP if (!) ((strcmp($row_rsCategories['mcategory'],$row_rsCategories['id'])))) {echo ' checked =------'checked\' ' ;}?} > name = "category []" type = "checkbox" value = "<?" PHP echo $row_rsCategories ['id'];? ">" / > <? PHP echo $row_rsCategories ['category'];? > < br / >
<? PHP} while ($row_rsCategories = mysql_fetch_assoc ($rsCategories));? >
what I have here results:
all categories displayed twice with selected categories of table 2 verified = by the results of sql when running alone
Attempt 2
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
CAT categories
LEFT JOIN members_categories mcat WE mcat.category = cat.id
WHERE mcat.member_id = ' "." $_GET ['id']. »"
ORDER BY category ASC
(run on its own, all categories of table 1 who have a match in the table 2 and none of the other in table 1 shows)
area of the form with checkboxes:
even the first attempt
what I have here results:
all categories selected in table 2 shows and checked, and no other choices of table 1 = by the results of sql when running alone
Attempt 3
My sql:
SELECT cat.id, cat.category, mcat.category as mcategory
THE CAT of categories, members_categories mcat
WHERE mcat.member_id = ' "." $_GET ['id']. »"
GROUP BY cat.id
ORDER BY category ASC
(running his own, all the choices in the category of table 1 are displayed, however, the mcategory column displays the lowest category numbered (same one) against all of these options rather then correspond to their.)
area of the form with checkboxes:
even the first attempt
what I have here results:
all choice of category in table 1 are displayed, however, only the first category in table 2 (which in this case is the lowest number) is marked as checked with the checkboxe, even if there is more then one category in table 2 = by the results of sql when running alone
so, can anyone help? I'm just banging my head against the wall here is something missing that should be obvious, because the sql is not giving me what I need to work with the form in a loop region. Perhaps another approach should be taken and I have change the loop as well, but I think that this can be resolved with the sql. Thanks in advance.
Well, you can use two separate sql queries...
one with the names of the categories
and the second nested with the loop that references the id of category in table 1 to pair with table 2
-
Digital limit - several tables and 1 table limit test
Hello!
I am quite new to Teststand and I'm stuck with a problem whose solution should not be otherwise complex... (I think...).
I would use a "limit test digital"vi (LabVIEW module). " This vi returns 3 paintings and I would define 1 "min/max" for each table.
that is to say:
Array1 => each element compared to min - 1 & max1
Array2 => each element compared to min2 & max2
ARRAY3 => each element compared to min3 & max3
For 1 table, I found this solution: I write Locals.ARRAY1 [RunState.LoopIndex] 'DataSource' and all the elements of the array are compared to the limits that I chose. Of course, when I add 2 tables, the same limits are compared to these new windows but I would allocate 1 limits given in table 1.
Does anyone have an idea of an easy solution?
My code Teststand and the small vi are here below if this might help.
Thank you in advance!
Consider this example. The trick is to repeat a measurement on the Data Source tab.
-
Joining several tables in Oracle DB
I have the following tables.
1 AddProject
-PROJID
-projName
2 AddLab
-Labrador
-teacher
3 ProjLabAssociation
-PROJID
-Labrador
4 AddResearchArea
-raID
-raName
5 ProjRAAssociation
-PROJID
-raID
AddProject is associated with tables-AddLab and AddResearchArea
ProjLabAssociation and ProjRAAssociation are the association of the tables that contain the primary key of the corresponding tables. The two fields in these 2 tables are primary keys.
If AddProject has 3 entrances - (Proj1, ProjectA) (Proj2 ProjectB), (Proj3, ProjectC)
AddLab has 2 entrances - (Lab1, Bangalore), (Lab2, Chennai)
AddResearchArea has 2 inputs - AM1 (Green Computing) (RA2, Cloud Computing)
ProjLabAssociation has 2 entrances - (Proj2 Lab1), (Proj3, Lab1)
ProjRAAssociation has 3 entries - (Proj2 RA1), (Proj3, AM1), (Proj3, RA2)
If I ask by AddLab given for (Lab1, Bangalore), I should get the following columns in the result table
--------------------------------------------------------------------------------------------------------------------------------
Table2ID | Table2Name | Table3ID | Table3Name | Table1ID | Table1Name
Lab1. Bangalore | RA1 | Green Computing | Proj2 | Project b
Lab1. Bangalore | RA1 | Green Computing | Proj3 | Project c
Lab1. Bangalore | RA2 | Cloud Computing | Proj3 | Project c
--------------------------------------------------------------------------------------------------------------------------------
I tried the following commands but I m getting the expected result
1.
A SQLException exception is thrown by saying - java.sql.SQLException: ORA-01417: a table can be external joined as another tableSELECT * FROM AddLab al, ProjLabAssociation pl, AddProject ap WHERE al.labID = pl.labID(+) and ap.projID = pl.projID(+);
--------------------------------------------------------------------------------------------------------------------------------
2.
I do not get results expcted hereSELECT * FROM AddLab,AddProject,AddResearchArea WHERE labID in (select al.labID from ProjLabAssociation pl,AddLab al where al.labID = pl.labID) AND projID in (select ap.projID from ProjLabAssociation pl,Addproject ap where ap.projID = pl.projID) AND themeID in (select ar.raID from ProjRAAssociation pr, AddResearchArea ar where ar.raID = pr.raID) AND projID in (select ap.projID from ProjRAAssociation pr,Addproject ap where ap.projID = pr.projID) ORDER BY labID;
--------------------------------------------------------------------------------------------------------------------------------
Oracle version: 9i 10g / 11g
Can anyone help me in this.
Published by: user9205634 on December 22, 2011 03:40Hello
Below the code gives the result
with table1 as ( select 'Proj1' as table1id,'ProjectA' as table1name from dual union all select 'Proj2' as table1id,'ProjectB' as table1name from dual union all select 'Proj3' as table1id,'ProjectC' as table1name from dual union all select 'Proj4' as table1id,'ProjectD' as table1name from dual ) ,table2 as ( select 'Lab1' as table2id,'Bangalore' as table2name from dual union all select 'Lab2' as table2id,'Chennai' as table2name from dual union all select 'Lab3' as table2id,'Delhi' as table2name from dual ) , table3 as ( select 'RA1' as table3id,'Green Computing' as table3name from dual union all select 'RA2' as table3id,'Cloud Computing' as table3name from dual ) ,table1table2 as ( select 'Proj2' as table1id,'Lab1' as table2id from dual union all select 'Proj3' as table1id,'Lab1' as table2id from dual union all select 'Proj3' as table1id,'Lab2' as table2id from dual union all select 'Proj4' as table1id,'Lab3' as table2id from dual ) ,table1table3 as ( select 'Proj2' as table1id,'RA1' as table3id from dual union all select 'Proj3' as table1id,'RA1' as table3id from dual union all select 'Proj3' as table1id,'RA2' as table3id from dual ) select t2.table2id,t2.table2name,t3.table3id,t3.table3name,t1.table1id,t1.table1name from table1 t1,table2 t2,table3 t3,table1table2 jt1t2,table1table3 jt1t3 where jt1t2.table2id=t2.table2id and t1.table1id=jt1t2.table1id and jt1t3.table1id(+)=jt1t2.table1id and t3.table3id(+)=jt1t3.table3id order by t2.table2name,t3.table3id;
TABLE2ID TABLE2NAME TABLE3ID TABLE3NAME TABLE1ID TABLE1NAME -------- ---------- -------- --------------- -------- ---------- Lab1 Bangalore RA1 Green Computing Proj2 ProjectB Lab1 Bangalore RA1 Green Computing Proj3 ProjectC Lab1 Bangalore RA2 Cloud Computing Proj3 ProjectC Lab2 Chennai RA1 Green Computing Proj3 ProjectC Lab2 Chennai RA2 Cloud Computing Proj3 ProjectC Lab3 Delhi Proj4 ProjectD 6 rows selected
Kind regards
Prabhu -
Problem with joining several tables
Hello PL/SQL gurus and experts.
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
I followed two tables
Student-
Fees-drop table TT3; create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select 1,11,21,'Mike',25 from dual union all select 2,12,22,'Clark',26 from dual union all select 1,11,21,'Mike',27 from dual union all select 4,17,27,'Ussan',28 from dual union all select 5,13,21,'Linda',29 from dual union all select 6,14,24,'Obrek',35 from dual union all select 7,15,25,'Batty',45 from dual union all select 8,16,26,'Nicky',38 from dual union all select 1,11,21,'Mike',25 from dual union all select 2,12,22,'Clark',26 from dual union all select 1,11,21,'Mike',27 from dual union all select 4,17,27,'Ussan',28 from dual union all select 5,13,21,'Linda',29 from dual union all select 6,14,24,'Obrek',35 from dual union all select 7,15,25,'Batty',45 from dual union all select 8,16,26,'Nicky',38 from dual ;
I am looking forward to the fees, commissions and surcharges output for each student and by using the following SQL code.drop table TT4; create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select 1,11,21,25000,4456,223 from dual union all select 2,12,22,356000,3321,0 from dual union all select 1,11,21,456000,223,33 from dual union all select 4,17,27,32890,0,0 from dual union all select 5,13,21,0,778,223 from dual union all select 6,14,24,332567,222,0 from dual union all select 7,15,25,228990,22,0 from dual union all select 8,16,26,0,0,2234 from dual union all select 1,11,21,22345,0,0 from dual union all select 2,12,22,2222789,2,33 from dual union all select 1,11,21,334567,0,0 from dual union all select 4,17,27,9987250,2,33 from dual union all select 5,13,21,2227890,0,0 from dual union all select 6,14,24,2278231,0,3345 from dual union all select 7,15,25,223456,2,0 from dual union all select 8,16,26,223890,0,0 from dual ;
but it gives me not the correct result and showing a lot of entries and display only the "Expenses" column then only I'm looking for the output to be -select t3.Name,t3.age,t4.Fees from tt3 t3, tt4 t4 where t3.FeesCntlr=t4.FeesCntlr union select t3.Name,t3.age,t4.Commission from tt3 t3, tt4 t4 where t3.CommCntlr=t4.CommCntlr union select t3.Name,t3.age,t4.Latepayment from tt3 t3, tt4 t4 where t3.LatePayCntlr=t4.LatePayCntlr
Kindly help me with this. Thank you in advance for your time and effort.Name Age Fees Commission Laypayment Mike 25 837912 4679 256 Clark 26 2578789 3323 33 Ussan 36 10020140 2 33 Linda 38 2227890 778 223 Obrek 38 2610798 222 3345 Batty 32 452446 24 0 Nicky 23 223890 0 2234
Hello
I see your table TT3 has duplicated lines. A reason for this?
Rather than run a separate, I created it without duplicated lines:
create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select 1,11,21,'Mike',25 from dual union all select 2,12,22,'Clark',26 from dual union all select 4,17,27,'Ussan',28 from dual union all select 5,13,21,'Linda',29 from dual union all select 6,14,24,'Obrek',35 from dual union all select 7,15,25,'Batty',45 from dual union all select 8,16,26,'Nicky',38 from dual; create table TT4(FeesCntlr,CommCntlr,LatePayCntlr,Fees,Commission,Latepayment) as select 1,11,21,25000,4456,223 from dual union all select 2,12,22,356000,3321,0 from dual union all select 1,11,21,456000,223,33 from dual union all select 4,17,27,32890,0,0 from dual union all select 5,13,21,0,778,223 from dual union all select 6,14,24,332567,222,0 from dual union all select 7,15,25,228990,22,0 from dual union all select 8,16,26,0,0,2234 from dual union all select 1,11,21,22345,0,0 from dual union all select 2,12,22,2222789,2,33 from dual union all select 1,11,21,334567,0,0 from dual union all select 4,17,27,9987250,2,33 from dual union all select 5,13,21,2227890,0,0 from dual union all select 6,14,24,2278231,0,3345 from dual union all select 7,15,25,223456,2,0 from dual union all select 8,16,26,223890,0,0 from dual ; SELECT t3.name, t3.age, SUM (t4.fees) fees, SUM (t4.commission) commission , SUM (t4.latepayment) latepayment FROM tt3 t3, tt4 t4 WHERE t3.feescntlr = t4.feescntlr AND t3.commcntlr = t4.commcntlr AND t3.latepaycntlr = t4.latepaycntlr GROUP BY t3.name, t3.age; Output: NAME AGE FEES COMMISSION LATEPAYMENT ----- ---------- ---------- ---------- ----------- Mike 25 837912 4679 256 Ussan 28 10020140 2 33 Linda 29 2227890 778 223 Clark 26 2578789 3323 33 Obrek 35 2610798 222 3345 Nicky 38 223890 0 2234 Batty 45 452446 24 0
Kind regards.
AlPublished by: Alberto Faenza on November 6, 2012 12:40
-
Join several tables of two different patterns - is it possible?
If this is the case, what are the measures?
THXThis is the case.
You must prefix the tables with the schemaname tables is in, or create a synonym for the table. In addition, you must grant select rights from of a the reference schema owner schema:
SELECT A.*,B.* FROM SCHEMA1.TEST_TABLE A, SCHEMA2.TEST_TABLE B WHERE somecondition
-
Protect a document while allowing the insertion of data in a table and the points on a graph.
I created a Word document that contains a table and a chart. Can I protect document but allow data entry in the table and allow points appear in the table using Adobe?
Hi brianh89327665,
While you can apply a permissions password to a PDF file to prevent things such as printing and editing the document, you can not apply it selectively to parts of the PDF file.
Best,
Sara
Maybe you are looking for
-
Re: Satellite L655-11J flash map F8 missing 8.1 Win
First I searched on the internet I've read so many threads on this subject but none is regarding my problem.My wireless card is Broadcom 8.11n + + with ID PCI\VEN_14E4 & DEV_4727 Is not supported by new PVAT flash cards which I had to install in Wind
-
activation of the iPad or (lost?)
2016/2/4, in the morning, my ipad still worked as my clock. I checked my ipad for fb message after lunch, my ipad said he was lost and deleted. Enter the Apple ID and password that were used to put in place this ipad. It's my ipad bought on apple sto
-
to detect the meter output via the parallel port
I need to detect the meter count trigger, to perform an operation every time. I think passing the input signal pins (pins of status or control). The meter uses is omron H7EC. I lowered the voltage of 24 V to 5 v with resistors. But I can't get the en
-
"remove and check ink cartridges" error on HP 2401
ORIGINAL TITLE: Print printer print Recently, I replaced print cartridges on my HP 2401 printer. Printer has worked for a few weeks, and now an error that says: "remove and check print cartridges. I did this (interface buvardages print cartridge on
-
Error in the configuration wizard. Unable to connect to the router.
All connections are correct. I am able to connect to IE and FireFox with ethernet and connected my corner via "Linksys". I opened with ISP address and configure security. Is there more in the configuration I have to do?