How to join two tables using EJB-QL
Hi There,
How to join tables using EJB-QL ?
Thanks.
Edited by: vamseebobby on Nov 6, 2007 8:12 AM
You might try
SELECT b.entity2property FROM Entity1 a JOIN a.entity2 b
for example, to retrieve players names, from a Players table, that belong to the team 'My Team' in the Teams table
SELECT b.playerName FROM Teams a JOIN a.players b WHERE a.teamName = 'My Team'
Similar Messages
-
How to Join two tables using the Inner Join
Hi All,
I have two tables i.e table1 and table2 as i have created two otds and my present requirement is to join this two tables and get the results and using this i need to do some logic and update another table3.
can some one help me out how to go for the above req.
Thanks in Advance
SrikanthThe best efficient way to use inner join is create two input otds,use there otd's in create a collaboration usinf etl.
after selecting two input otd's create a inner join statement and map it to out put otd.
while using the etl the performance of the over all integration is increased 20 time of the normal integration.
Hopes this will helps,,
Thanks,
Papa Rao. -
How to join two tables using UD Connect ?
Hi,
I have 2 tables on which I need to create join & extract the data from Oracle database using UD connect. Is this possible? If yes, please let me know how or suggest an alternative approach.
Thanks,
SunilThanks Tony for the reply.. Actually, the issue is Netweaver Java dictionary doesn't allow you to create a view, right? Also, I dont want to create a view directly on the database.
I want to handle this on BI side somehow. -
hi
how to join two tables using inner join if the first table has two primary keys and second table has 3 primary keysWould describe type of joins in ABAP, which might differ with other joins.
The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
At least one comparison must be specified after ON.
Individual comparisons may be joined using AND only.
All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
The following additions not be used: NOT, LIKE, IN.
No sub-queries may be used.
For outer joins, only equality comparisons (=, EQ) are possible.
If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
Resulting set for inner join
The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
Resulting set for outer join
The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
Note
If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
Example
Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
PARAMETERS: p_cityfr TYPE spfli-cityfrom,
p_cityto TYPE spfli-cityto.
DATA: BEGIN OF wa,
fldate TYPE sflight-fldate,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa.
DATA itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY fldate carrname connid.
SELECT ccarrname pconnid f~fldate
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( scarr AS c
INNER JOIN spfli AS p ON pcarrid = ccarrid
AND p~cityfrom = p_cityfr
AND p~cityto = p_cityto )
INNER JOIN sflight AS f ON fcarrid = pcarrid
AND fconnid = pconnid ).
LOOP AT itab INTO wa.
WRITE: / wa-fldate, wa-carrname, wa-connid.
ENDLOOP.
Example
Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
PARAMETERS p_cityfr TYPE spfli-cityfrom.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
AND p~cityfrom = p_cityfr.
LOOP AT itab INTO wa.
IF wa-connid = '0000'.
WRITE: / wa-carrid, wa-carrname.
ENDIF.
ENDLOOP. -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
Join two table using two link field
hi all
i need to left join two table, and to link two table need to match two field
ex: the link field is store_name and id
i use below sql statement
SELECT A1.store_name, A1.id, A1.card, A2.sale, A2.history
FROM Georgraphy A1, Store_Information A2
WHERE A1.store_name = A2.store_name(+)
AND A1.id = A2.id(+)
but it's wrong
please tell me how to left join A1 and A2, thx!Whats your aim?
Any error message?
SQL> select * from geography;
ID STORE_NAME
1 a
1 b
2 a
2 b
SQL> select * from store_information;
ID STORE_NAME
1 a
3 d
SQL> SELECT *
2 FROM Geography A1, Store_Information A2
3 WHERE A1.store_name = A2.store_name(+)
4 AND A1.id = A2.id(+);
ID STORE_NAME ID STORE_NAME
1 a 1 a
2 a
2 b
1 b -
How we relate two tables using foreign key(fk)?
hi to all,
what are the conditions has to follow to relate two tables.I.e.,
the two tables have same primary keys(pk). if we relate these two tables in one table the pk and fk will be the same then how that table in active.Hi
To relate two tables..we have foreign key relationship.
In one table v have primary key and in the second table, the same key is foreign key for that table..
To relate two tables, we can use JOINS
If there is already a suitable foreign key between two tables used in the view, these tables can be linked with a join condition from this foreign key.
Create a view on tables TAB1 and TAB2. TAB1 is the primary table of the view. TAB2 is the secondary table of the view. TAB1 is the check table for TAB2. The foreign key fields are assigned to the check table fields as follows:
TAB1-FIELD_A assigned to TAB2-FIELD_1
TAB1-FIELD_A assigned to TAB2-FIELD_1
The join condition of the view generated from the foreign key is then:
CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B.
Join conditions can also be copied from generic and constant foreign keys. If a constant is assigned to a field in the foreign key, it is also assigned to the field in the join condition. There is no join condition for a generic relationship in the foreign key.
The foreign key between tables TAB1 (check table) and TAB2 (foreign key table) is defined as follows:
TAB1-FIELD_A assigned to TAB2-FIELD_1
TAB1-FIELD_B generic
TAB1-FIELD_C assigned to constant C
The join condition for the view generated from the foreign key is in this case:
CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = C.
Hope it helps
Reward if useful. -
Hi Gurus,
I have three tables. I want to join all tables using union in SQL statement. The query is returning all the records from both tables but i only require unique rows based on a specific column value. Here is my table structure -
TableA -
LIC_ID NUMBER(10) NOT NULL
LIC_NUMBER VARCHAR2(20)
COMMENCE_DATE DATE
EXPIRY_DATE DATE
TERM VARCHAR2(20)LIC_ID is the primary key in this table -
Sample data from TableA
LIC_ID LIC_NUMBER COMMENCE_DATE EXPIRY_DATE TERM
2 TR4323 12/04/2008 11/03/2010 2 Years
34 TR5432 23/07/2009 22/07/2010 1 Year
45 TR5321 24/06/2009 23/06/2010 1 Year
65 TR6666 23/07/2010 22/07/2011 1 Year
32 TR2423 30/05/2010 29/05/2011 1 YearTableB -
MAR_ID NUMBER(10) NOT NULL
LIC_ID NUMBER(10) NOT NULL
ZONE_NAME VARCHAR2(20)
DEPARTMENT VARCHAR2(20)
ACTIVITIES VARCHAR2(200)
COMMENTS VARCHAR2(200)MAR_ID is the primary key in this table and LIC_ID is the foreign key on TableA
Sample data from TableB -
MAR_ID LIC_ID ZONE_NAME DEPARTMENT ACTIVITIES COMMENTS
23 2 ZONE A IT NONE
43 34 ZONE B IT NONE
33 65 ZONE C ACCOUNT NONE
TableC
REC_ID NUMBER(10) NOT NULL
LIC_ID NUMBER(10) NOT NULL
DIST_NAME VARCHAR2(20)
REGION VARCHAR2(20)
ACTIVITIES VARCHAR2(200)
COMMENTS VARCHAR2(200)REC_ID is the primary key in this table and LIC_ID is the foreign key.
Sample data -
REC_ID LIC_ID DIST_NAME REGION ACTIVITIES COMMENTS
2 45 SA NORTH NONE
3 65 TA NORTH NONE
5 32 NT SOUTH NONEHere is my sql query -
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableB b
where a.lic_id=b.lic_id
union
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableC c
where a.lic_id=c.lic_idThe above query returns -
lic_id lic_number commence_date expiry_date
2 TR4323 12/04/2008 11/03/2010
34 TR5432 23/07/2009 22/07/2010
45 TR5321 24/06/2009 23/06/2010
65 TR6666 23/07/2010 22/07/2011
32 TR2423 30/05/2010 29/05/2011
65 TR6666 23/07/2010 22/07/2011 LIC_ID 65 exists in both table TableB and TableC hence it repeats in query but I want to display that only once. How can I do that? I want to return unique record on LIC_NUMBER.
Hope this make sence.
Many thanks,
TajuddinThanks for all your reply and suggestions. David altering session did not work.
Sven your idea helped me to figure it out what to do. I found a way around to fix it. Here is my current code -
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableB b
where a.lic_id=b.lic_id
union
select a.lic_id, a.lic_number, a.commence_date, a.expiry_date from
TableA a, TableC c
where a.lic_id=c.lic_id and c.lic_id not in ( select lic_id from TableB)This will exclude any LIC_ID exists in TableB.
Thanks again for your help guys.
Regards,
M Tajuddin
Web: http://tajuddin.whitepagesbd.com
Blog: http://aspblog.whitepagesbd.com -
Joining two tables using PL/SQL
here i am trying to join two tables can any one tell me what is wrong with this syntex
CREATE OR REPLACE PROCEDURE test IS
CURSOR c1 IS SELECT seq,fname,lname from t1;
CURSOR c2 IS SELECT seq1,q,a from t2;
userjob number;
BEGIN
OPEN c1;
insert into t3 values(c1.seq,c1.fname,c1.lname);
FETCH c1.seq INTO userjob;
FOR c1rec IN c2 LOOP
IF (c1rec.seq=c1.seq and c1rec.q1='why') THEN
insert into t3 values(c1rec.q1,c1rec.a1);
elsif (c1rec.seq=c1.seq and c1rec.q1='what') then
insert into t3 values(c1rec.q2,c1rec.a2);
elsif (c1rec.seq=c1.seq and c1rec.q1='when') then
insert into t3 values(c1rec.q3,c1rec.a3);
elsif (c1rec.seq=c1.seq and c1rec.q1='where') then
insert into t3 values(c1rec.q4,c1rec.a4);
END IF;
END LOOP;
END;
/You should always fetch a cursor before using it's values. All columns in the select should be fetched into variables or a record-variable. You can't refer to the cursor-columns values with c1.seq etc.
r1 c1%rowtype;
l_found boolean;
BEGIN
OPEN c1;
FETCH c1 INTO r1;
insert into t3 values(r1.seq,r1.fname,r1.lname);
l_found := c1%found;
close c1;
if l_found
then
It is also better to close the cursor and check if the select resulted in a row. With this code you will only retrieve one row even if the select will result in multiple rows.
But I agree with all the others that this can probably be done more efficiently with one SQL statement. -
How to join two tables with no similar columns
Hi all,
I have two tables as follows:
Table T1 have Attributes as follows:
GLCODE,
BRANCH,
ITEM_NUMBER,
DEMAND_DATE,
QUANTITY,
SOURCE
Table T2 have Attributes as follows:
FORECAST_DATE
Now in SQL if run the following stattement iam getting out put.
SELECT GLCODE,BRANCH,ITEM_NUMBER,DEMAND_DATE,QUANTITY, SOURCE,(SELECT DISTINCT FORECAST_DATE FROM T2) FROM T1
The above SQL Statement giving correct results for me.
The same SQL Statement how can we implement in mapping level?
Regards,
AvaJaap van,
>
You have to specify an outer join, but how do you do that if there is no join to begin with? I would do the following (which I didn't test yet):
add an extra column (say C_JOIN) to the T2-ingroup of the join operator and fill it with from a constant operator with say value 1. Then use T2.C_JOIN (+) = 1 as the join condition.
If every record in T2 is guaranteed to have the same value, instead of using a deduplicator, which will read all records, sort them and deduplicate them, you can use a filter with filter condition ROWNUM < 2, which only will read one record.
I am facing almost the same problem but not entirely thou and I was wondering if you have an idea how to even start.
Problem:
I got this table:SQL> desc ita.tpis32_job_status
Name Null? Type
JOBID NOT NULL NUMBER
T1_ID NUMBER
QID NUMBER
REQ_TYPE VARCHAR2(10)
SUBMIT_TIME DATE
OWNERID VARCHAR2(30)
DESCRIPTION VARCHAR2(150)
STARTTIME DATE
ENDTIME DATE
STATUS VARCHAR2(50)
ERROR_ID NUMBER
TABLE_NAME VARCHAR2(30)
SERVER_ID VARCHAR2(10)
DATABASE VARCHAR2(20)
PRIORITY NUMBER
NUM_LINES NUMBER
PROCESS_ID NUMBER
QUE_TIME NUMBER
STATUS_CODE NUMBER
ERROR_MSG VARCHAR2(500)
NUM_LINES_TS NUMBER
REMOTE_STATUS NUMBER
This the above table, i am looking for JOBID (a five digit number) like 25875.
What I want to do is add or append this five digit number to a string to find the corresponding table in dba_tables or all_tables. The only way I have try to do this is by writing PLSQL as you see from here:
Re: Use PLSQL to delete tables dynamically
When the select is writing properly, the result of the five digit number from JOBID and the string should look like the below result (job_(five digit_%).
My problem is there is no relationship between ALL_TABLES and the my own table (ita.tpis32_job_status). Any help will be appreciated.
TABLE_NAME
JOB_58871_OUTDATA
JOB_58868_TS
JOB_58868_OUTDATA
JOB_58867_TS
JOB_58867_CMDLBL_2
JOB_58867_OUTDATA
JOB_58866_TS -
How to join two tables such as union all
We have two tables ,there has the same structure,one is the recent Table,the other is a history Table。How can i get the reasult from the two tables .
I know we can create the table using table type=select and write the SQL.
I want to know another way such as fragmentaion content,But i don`t know how to implement.
Who can give the step by step .
Thank you very much.I set the wrong case .my question has been answered..
Thank you ~
Edited by: Richard 1982 on 2009-12-27 下午9:55 -
How to join two tables and get the supply delivery date next to order?
So there are two tables. One has customer's order no, ordered date, order quantity, available quantity and code of article-
The other table comes form supply side where we have supply order no, article number, ordered qty, and delivery date.
We keep stock so this can not be MOT (made to order) system.
What i need is correct date of arrival to appear next to cusotmers spoecirfic order. The older cusotmers order get's the parts first, second oldest order is next in line etc.
here is any example
customer's order
ref order
art. code
ordered qty
available qty
order date
1809202491
700497
60
0
3.7.2014
1809200528
700497
13
0
20.6.2014
1809198640
700497
7
0
9.6.2014
supply order
supply order
art. code
qty orderd
date of arrival
4501243378
700497
50
4.8.2014
4501263437
700497
20
6.10.2014
There is actually a 3rd "table" and that sort of connects the two and that is stock on hand per art. code.
The main issue is that stock is assigned to purchase orders only when it actually arrives in the warehouse.
A human can easilly connect the dates of when the stock will arrive and quantities with correct customer's order. In this case the firts order will get 50 pcs in August while 10 pcs will remain on backorders. The missing 10 pcs Will arrive in October. The second order will get 10 pcs in october and 3 will remain on backorders with no delivery date. While the third customer orders does not have a delivery date.
So how to make the SAP do this calculations and display the arrival date next to date of customer's order?I checked the instructions as i do not have access to this part. It seem this is a query. We had issues with queries in the past as not all codes from orders would appear in them. They never found the reason why that is happening.
However, I think the main issue is that the information here is not connected and is separately provided for supply and for sales. So i doubt it can be connected in this query.
edit: as you can see the only connection is stock on hand.
and total number of various items we have is close to 100.000 of various article codes. -
How to join two tables in a cursor
i have a cursor that selects data from one table,
i want it to select data from one other table also.. how i can do that.. is there any alternate way to do that if yes then suggest .. waiting for ur reply....employee_number" and other has column name as "comp_employee_number" .. Well that would be quite simple ....
SELECT e1.foo, e2.bar
FROM employees e1, staff_members e2
WHERE e1.employee_number = e2.comp_employee_number;.... unless what you're really expecting is for the datbase to somehow figure out by itself that although those columns have different names they actually represent the same data and magically derive the join for you.
Perhaps, you really need to explain in more detail precisely what your problem is.
Cheers, APC -
How to join two tables without constraints??
I want get the tables to be joined without constraints!!
table1 :
100 get
101 wet
102 set
and
table 2 :
10 xxx
11 yyy
12 zzz
I got the output like this,
output :
ID NAME ID NAME
101 wet 10 xxx
101 wet 12 zzz
101 wet 11 yyy
100 get 10 xxx
102 set 11 yyy
102 set 10 xxx
100 get 11 yyy
100 get 12 zzz
102 set 12 zzz
but i want everything to be written once.
Help me out with this!!???Tanx fr the response!
Nah, but me used toad to run it. And my query is
QUERY 1 :
SELECT * FROM PARTES P,CUSTES C
WHERE (P.ID,P.NAME,C.ID,C.NAME) IN (SELECT P1.ID,P1.NAME,C1.ID,C1.NAME
FROM PARTES P1,CUSTES C1)
QUERY 2 :
select id as pid, name as name from partes
union
select id as pid,name as name from custes;
OUTPUT FOR QUERY2 IS,
PID NAME
10 xxx
11 yyy
12 zzz
100 get
101 wet
102 set
In the 2nd query am getting the joined records of both the tables. But my need is both the tables record to be displayed like this
ID NAME ID_1 NAME_1
10 xxx 100 get
11 yyy 101 wet
12 zzz 102 set
What i am trying is,i want to join the all the columns parallely in my output!!
Is there any source mike? -
How can join two tables if column values does not match
Hi guys,
i have table
col1 col2
abcd 123
asdf 234
wert 456
sedf 789
and another table with
col1
abcd
aaaa
but i need the output like
abcd 123
abcd 234
abcd 456
abcd 789
aaaa 123
aaaa 234
aaaa 456
aaaa 789You do not tell us about this where condition before, but...
select b.col1, a.col2 from table a, another_table b
where a.col2 in (123, 234, 456, 789)or
select b.col1, a.col2 from table a, another_table b
where a.col1 in ('abcd','asdf','wert','sedf' )
Maybe you are looking for
-
Iphone 5s ios 7.1 siri male voice buggy
After upgrade to 7.1 Siri British male voice is buggy, low quality sound, mispelling. I had to change it into female voice! Anyone else?
-
Getting error in Oracle EDQP Webservice call using Soap UI
Hi , I am trying to use Oracle EDQP webservice : http://<<hostname>>:<<port>>/datalens/ws/Processor when i trying to access the processOneLine or processList operation, i am getting the follwing error: <faultstring>oracle.pdq.api1.minicore.SaDetailEx
-
Warning - When Compiling .jsp pages under WEB-INF
Created a directory jsp under WEB-INF and when i compile the jsp pages i get the following warning message Warning: package name web2d_inf._jsp does not match source file name C:\ProviderEnrollment\ProvEnrollView\classes\.jsps\_WEB_2d_INF\_jsp\_searc
-
I get this message for all of my Adobe Creative Suite CS4 applications. Just loaded everything onto a new computer from my backup drive. I have tried all of the recommendations here. I don't know what to do now. None of the files exist that I'm suppo
-
I have a report, which has "Layout" and "Export file path" fields on selection screen. I need to export the report to CSV file in the format of dynamical layout while executing on background. In this case: 1. How do I read the structure of layout bef