Mapping Suggestions 3 table join
I have 3 existing tables which can't be changed:
Table A
A_ID
B_FK
A_DATE
Table B
B_ID
C_FK
Table C
C_ID
C_DATE
C_VALUE
MyClass needs:
A_ID
A_DATE
C_VALUE
where
A_DATE = C_DATE
C_ID = C_FK
B_ID = B_FK
The SQL is easy, but how do I map it in Toplink. If I use multi table info I can only define a single table reference for each table.
Any suggestions?
Simon
Don
Thanks for your reply.
I already had two classes A/BClass with a one to one to CClass but I still couldn't create the FK relationships I wanted in the Mapping Workbench. In the end I took a simple view and just simply added the FK relationships directly as below:
OneToOneMapping cMapping = new OneToOneMapping();
cMapping.setAttributeName("c");
cMapping.setReferenceClass(com.syncron.model.CStuff.class);
I re-structured the foreign key set up as if it were SQL
cMapping.addForeignKeyFieldName("TABLE_B.C_FK", "TABLE_C.C_ID");
cMapping.addForeignKeyFieldName("TABLE_A.A_DATE", "TABLE_C.C_DATE");
descriptor.addMapping(cMapping);
This solution was fine, its just a shame the Workbench can't hold this relationship, as in the data model I'm looking at it seems to be a common problem. Maybe a suggestion for the future?
Thanks again.
Simon
Similar Messages
-
Opinion needed on best way to map multiple table joins (of the same table)
Hi all
I have a query of the format:
select A.col1, B.col1,C.col1
FROM
MASTER_TABLE A, ATTRIBUTE_TABLE B, ATTRIBUTE_TABLE C
WHERE
A.key1 = B.key1 (+)
AND
A.key1 = C.key1(+)
AND
B.key2(+) = 100001
AND
C.key2(+) = 100002
As you can see, I am joining the master table to the attribute table MANY times over, (over 30 attributes in my actual query) and I am struggling to find the best way to map this efficiently as the comparison for script vs. mapping is 1:10 in execution time.
I would appreciate the opinion of experienced OWB users as to how they would tackle this in a mapping and to see if they use the same approach as I have done.
Many thanks
AdiSELECT external_reference, b.attribute_value AS req_date,
c.attribute_value AS network, d.attribute_value AS spid,
e.attribute_value AS username, f.attribute_value AS ctype,
g.attribute_value AS airtimecredit, h.attribute_value AS simnum,
i.attribute_value AS lrcredit, j.attribute_value AS airlimitbar,
k.attribute_value AS simtype, l.attribute_value AS vt,
m.attribute_value AS gt, n.attribute_value AS dt,
o.attribute_value AS datanum, p.attribute_value AS srtype,
q.attribute_value AS faxnum,
R.ATTRIBUTE_VALUE AS FAXSRTYPE,
s.attribute_value AS extno,
t.attribute_value AS tb, u.attribute_value AS gb
v.attribute_value AS mb, w.attribute_value AS stolenbar,
x.attribute_value AS hcredit, y.attribute_value AS adminbar,
z.attribute_value AS portdate
FROM csi_item_instances a,
csi_iea_values b,
csi_iea_values c,
csi_iea_values d,
csi_iea_values e,
csi_iea_values f,
csi_iea_values g,
csi_iea_values h,
csi_iea_values i,
csi_iea_values j,
csi_iea_values k,
csi_iea_values l,
csi_iea_values m,
csi_iea_values n,
csi_iea_values o,
csi_iea_values p,
csi_iea_values q,
CSI_IEA_VALUES R,
csi_iea_values s,
csi_iea_values t,
csi_iea_values u,
csi_iea_values v,
csi_iea_values w,
csi_iea_values x,
csi_iea_values y,
csi_iea_values z
WHERE a.instance_id = b.instance_id(+)
AND a.instance_id = c.instance_id(+)
AND a.instance_id = d.instance_id(+)
AND a.instance_id = e.instance_id(+)
AND a.instance_id = f.instance_id(+)
AND A.INSTANCE_ID = G.INSTANCE_ID(+)
AND a.instance_id = h.instance_id(+)
AND a.instance_id = i.instance_id(+)
AND a.instance_id = j.instance_id(+)
AND a.instance_id = k.instance_id(+)
AND a.instance_id = l.instance_id(+)
AND a.instance_id = m.instance_id(+)
AND a.instance_id = n.instance_id(+)
AND a.instance_id = o.instance_id(+)
AND a.instance_id = p.instance_id(+)
AND a.instance_id = q.instance_id(+)
AND A.INSTANCE_ID = R.INSTANCE_ID(+)
AND a.instance_id = s.instance_id(+)
AND a.instance_id = t.instance_id(+)
AND a.instance_id = u.instance_id(+)
AND a.instance_id = v.instance_id(+)
AND a.instance_id = w.instance_id(+)
AND a.instance_id = x.instance_id(+)
AND a.instance_id = y.instance_id(+)
AND a.instance_id = z.instance_id(+)
AND b.attribute_id(+) = 10000
AND c.attribute_id(+) = 10214
AND d.attribute_id(+) = 10132
AND e.attribute_id(+) = 10148
AND f.attribute_id(+) = 10019
AND g.attribute_id(+) = 10010
AND h.attribute_id(+) = 10129
AND i.attribute_id(+) = 10198
AND j.attribute_id(+) = 10009
AND k.attribute_id(+) = 10267
AND l.attribute_id(+) = 10171
AND m.attribute_id(+) = 10184
AND n.attribute_id(+) = 10060
AND o.attribute_id(+) = 10027
AND p.attribute_id(+) = 10049
AND q.attribute_id(+) = 10066
AND R.ATTRIBUTE_ID(+) = 10068
AND s.attribute_id(+) = 10065
AND t.attribute_id(+) = 10141
AND u.attribute_id(+) = 10072
AND v.attribute_id(+) = 10207
AND w.attribute_id(+) = 10135
AND x.attribute_id(+) = 10107
AND y.attribute_id(+) = 10008
AND z.attribute_id(+) = 10103
AND external_reference ='07920490103'
If I run this it takes less than a second in TOAD, when mapped in OWB it takes ages. 10:1 is a conservative estimate. In reality it takes 15-20 minutes. CSI_IEA_VALUES has 30 million rows CSI_ITEM_INSTANCES has 500,000 rows.
Hope that helps. I would love to know how others would tackle this query. -
Is Mapping Lookup table possible with IDOC to FIle scenario
Hi all,
Need suggestion, I am using SP16
My sceanrio is IDOC to FIles, and have to use a Mapping Lookup tables for some of the fields within the mapping...
'Crossref: PlantLoc_to_WhseComDiv. Value mapping lookup to take two fields from SAP and convert to WMS 3-digit value'
How to go with this, since i have checked in SAP library that it is for only RFC,JDBC,SOAP adapters ...
Need u r valuable inputs,
Regards,
sridharYou can use RFC or SOAP or JDBC lookup in your mapping.Why not?..It does not mean that we use the lookups only in RFC secnarios.You can use them in any scenario.
-
Table Join Insert Help?!
Hi guys,
I basily need to update just null 'start_date'(s) in TableB, with the 'start_date'(s) from TableA.
The tables join by claim_no.
I was trying alog the lines of this:
INSERT INTO TableB.start_date
SELECT TableA.start_date FROM TableA INNER JOIN TableB
ON TableA.Claim_no = TableB.Claim_no
WHERE TableB.start_date is null
But its returing 'column ambiguously defined'
Any suggestions? Im prob away of the mark here!!!
Thanks JPMYou need UPDATE instead of INSERT
UPDATE TableB
SET start_date = ( SELECT TableA.start_date
FROM TableA INNER JOIN TableB
ON TableA.Claim_no = TableB.Claim_no
WHERE start_date is nullRegards
Arun -
How to do hibernate mapping for table or view without a primary key
Hi,
Anyone knows how to do hibernate mapping for table or view without a primary key?
thanks.
ccor you can make all column primary key .Anybody seriously considering that as a good idea should understand the implications:
1. this requires that each row be unique - that's a minor issue normally, but can be a significant problem in some cases
2. in practically all databases, a primary key constraint creates a unique index - this has many implications:
a) in most databases, the index stores a copy of the column data that is indexed - this suggestion therefore more than doubles the data storage required for the data
b) whenever an indexed column is changed, the index has to be maintained - this suggestion then more than doubles the work that each UPDATE statement has to do, since both the table and the index have to be maintained for any UPDATE at all
This might work OK for toy projects, but it doesn't scale well at all... -
Hello,
First: I'm not an experienced Toplink user. We're using it in our project, but I think we're just using the most basic features. My portion of the project needs something slightly more sophisticated, and nobody here seems to know how it's done. So I turn to this forum for help.
The setup is fairly simple:
The "LOA" table has a "status" field, and bunch of other junk.
The "TACFC" table also has a "status" field, and a bunch of junk.
The "correlation" table has an OID, and the OID of an entry in table "LOA", and the OID of an entry in table "TACFC". It also has a few other bits of information about these correlations, such as dates, status, stuff like that.
In my Java code, I need to do a query, and get all correlation records where the correlated LOA (the one referred to by the LOA OID stored in the correlation record) has status == "A", and the correlated TACFC (identified by the TACFCOID in the correlation) has status == "A".
I'm pretty sure that toplink is correctly mapping the tables to objects, with the foreign keys, etc. It's just this expression that's giving me a headache.
Here's what I'm trying:
Expression exprPendingCorr = m_exprBuilder.get("correlationStatus").equal(globalProperties.CORRELATION_PENDING);
Expression exprCorrLOAAvailable = m_exprBuilder.anyOf("loa").get("status").equal(globalProperties.LOA_STATUS_AVAILABLE);
Expression exprCorrTACFCAvailable = m_exprBuilder.anyOf("tacfc").get("status").equal(globalProperties.TACFC_STATUS_AVAILABLE);
Expression exprCorrToActivate = exprPendingCorr.and(exprCorrLOAAvailable).and(exprCorrTACFCAvailable);
It builds just fine, but when I run it, I get:
EXCEPTION DESCRIPTION: Invalid use of anyOf() for a query key [oracle.toplink.mappings.OneToOneMapping[loa]] not representing a to-many relationship in an expression. Use get() rather than anyOf().
Now, I've been digging around in the documentation, reading about anyOf(), but I'm still stuck. Am I doing this the right way?
I'm going to post this now, and keep reading. I'm looking forward to any pointers, ridicule, or helpful suggestions on my problem.
Thanks! --- EricHi,
why don't you use "get" as the error message suggests?
Expression exprCorrLOAAvailable = m_exprBuilder.get("loa").get("status").equal(globalProperties.LOA_STATUS_AVAILABLE);
Expression exprCorrTACFCAvailable = m_exprBuilder.get("tacfc").get("status").equal(globalProperties.TACFC_STATUS_AVAILABLE);
It seems correlation -> LOA is a OneToOneMapping. You only need anyOf for a OneToManyMapping -
Sample coding for multiple table join
Hi,
i need a sample coding for multiple table join. can anyone help me out.
regards
GokulSELECT AVBELN AFKDAT AVTWEG ASPART AWAERK AKURRF AKUNAG AKNUMV
BPOSNR BFKIMG BNETWR BMATNR
DBEGRU ELABOR E~MATKL
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM VBRK AS A INNER JOIN VBRP AS B
ON AVBELN EQ BVBELN
INNER JOIN J_1IEXCHDR AS C
ON AVBELN EQ CRDOC
INNER JOIN KNVV AS D
ON DKUNNR EQ AKUNAG AND
DVKORG EQ AVKORG AND
DSPART EQ ASPART AND
D~BEGRU NE SPACE
INNER JOIN MARA AS E
ON EMATNR EQ BMATNR
WHERE A~FKDAT IN S_FKDAT AND
A~FKART EQ 'F2' AND
A~VTWEG IN S_VTWEG AND
A~SPART IN S_SPART AND
A~KUNAG IN S_KUNAG AND
A~FKSTO NE 'X' AND
B~WERKS IN S_WERKS AND
C~TRNTYP = 'DLFC' AND
E~LABOR IN S_LABOR AND
C~SRGRP IN ('01','02','03','31','32','33','41','42','43',
'81','82','83','95','55','45', '48') AND
B~MATNR IN S_MATNR AND
D~BEGRU IN S_BEGRU AND
E~MATKL IN S_MATKL.
but my suggestion not to use more than 2 table in inner join it will affect in performance use for all entries instead of join.
regards
shiba dutta -
Order Query in SQ01 using Table Joins in CRM
Hello Experts,
I am trying to create a query using table joins in SQ01 in CRM because I need a report that will give me all transactions for a selected Business Partner. I am unable to display any results when running my query. I have found other threads which give a list of possible tables to join together, but the fields used in the joins were not described.
The tables I have joined in my query are as follows:
CRMD_ORDERADM_H
CRMD_ORDER_INDEX
CRMD_PARTNER
BUT_000
I have used SE16 to try to search for additional tables to use for linking the Business Partner with a transaction, but I have been unsuccessful.
Would anyone please give advice as how to proceed?
Reward points are available!
Thank you in advance,
DavidDavid
The link with be the GUID.
CRMD_ORDERADM_H = Document Header Table
CRMD_ORDERADM_I = Document Line item Table
CRMD_LINK = Lists various link GUIDs, to
access order Information
The Table CRMD_ORDERADM_H will contain you transactions , once you find the GUID of your sales transaction in the table CRMD_ORDERADM_H.
You then need to check the table CRMD_LINK.
In this table you will then find a number in 11 = sales. This refers to the table CRMD_SALES. There are also links to many other tables ie Shipping, pricing, org etc.
CRMM_BUT_SET0140 - for Sales Group, Sales Office, District
CRMM_BUT_LNK0141 - for Sales Area data
Transaction CRMD_BUS2000115 allows you to see all sales transactions for a BP. CRMD_BUS2000126 shows you activities for selected BP.
Regards
M -
Context index can't be used in complicated multiple tables join?
hello
thank you for view this page.
i have a comlicated sql :
SELECT count(*)
from
((app_AssetBasicInfo left join app_AssetBasicInfoExt on
app_AssetBasicInfo.id=app_AssetBasicInfoExt.id) left join
(app_AssetCustominfo1 left join app_AssetCustominfoExt1 on
app_AssetCustominfo1.id=app_AssetCustominfoExt1.id) on
app_AssetBasicInfo.id=app_AssetCustominfo1.id) WHERE
app_AssetBasicInfo.CategoryID=1 AND Del_tag=0 and contains(description,'department')>0;
the table app_AssetBasicInfo and app_AssetBasicInfoExt have multiple columns and large recoord size. i create a context index on app_assetbasicinfoext(description) which description is 4000 varchar2.
but the sql doesn't use context index. i suspect that the complicated multiple table join can't use context index? does it correct?
thanks very much!Could you please post an explain plan? I'm not quite sure what is the issue.
-
Value Mapping through Tables in R/3 from XI
Hi All,
I'm new to XI and got a scenario as "Value Mapping through Tables in R/3 from XI". Kindly do tell me the steps which I should follow to complete this scenario. I'm from ABAP so table creation is known to me, what next should I do after table creation?
Thanks in Advance to all of you,
Sreedharsree,
value mapping are done using message mapping. In message mapping you have to make a RFC call to query the db and get the response. were you have to write a java function in mapping program.
check this blog, it speaks on value mapping
/people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i -
1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed in the stat plan ?
2. Does rowsource statistics gives some kind of understanding of Extended stats ?You can get Row Source Statistics only *after* the SQL has been executed. An Explain Plan midway cannot give you row source statistics.
To get row source statistics either set STATISTICS_LEVEL='ALL' in the session that executes theSQL OR use the Hint "gather_plan_statistics" in the SQL being executed.
Then use dbms_xplan.display_cursor
Hemant K Chitale -
Hi,
I built a query with 4 tables inside (load from Oracle DB and two of them are quite big, more than millions of rows). After filtering, I tried to build relationships between tables using Table.Join formula. However, the process took extremly long time to
bring out results (I ended the process after 15 mins' processing). There's a status bar kept updating while the query was processing, which is showed as . I suppose
this is because the query folding didn't working, so PQ had to load all the data to local memory first then do the opertion, instead of doing all the work on the source system side. Am I right? If yes, is there any ways to solve this issue?
Thanks.
Regards,
QilongHi Curt,
Here's the query that I'm refering,
let
Source = Oracle.Database("reporting"),
AOLOT_HISTS = Source{[Schema="GEN",Item="MVIEW$_AOLOT_HISTS"]}[Data],
WORK_WEEK = Source{[Schema="GEN",Item="WORK_WEEK"]}[Data],
DEVICES = Source{[Schema="GEN",Item="MVIEW$_DEVICES"]}[Data],
AO_LOTS = Source{[Schema="GEN",Item="MVIEW$_AO_LOTS"]}[Data],
Filter_WorkWeek = Table.SelectRows(WORK_WEEK, each ([WRWK_YEAR] = 2015) and (([WORK_WEEK] = 1) or ([WORK_WEEK] = 2) or ([WORK_WEEK] = 3))),
Filter_AlotHists = Table.SelectRows(AOLOT_HISTS, each ([STEP_NAME] = "BAKE" or [STEP_NAME] = "COLD TEST-IFLEX" or [STEP_NAME] = "COLD TEST-MFLEX") and ([OUT_QUANTITY] <> 0)),
#"Added Custom" = Table.AddColumn(Filter_AlotHists, "Custom", each Table.SelectRows(Filter_WorkWeek, (table2Row) => [PROCESS_END_TIME] >= table2Row[WRWK_START_DATE] and [PROCESS_END_TIME] <= table2Row[WRWK_END_DATE])),
#"Expand Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"WRWK_YEAR", "WORK_WEEK", "WRWK_START_DATE", "WRWK_END_DATE"}, {"WRWK_YEAR", "WORK_WEEK",
"WRWK_START_DATE", "WRWK_END_DATE"}),
Filter_AolotHists_byWeek = Table.SelectRows(#"Expand Custom", each ([WORK_WEEK] <> null)),
SelectColumns_AolotHists = Table.SelectColumns(Filter_AolotHists_byWeek,{"ALOT_NUMBER", "STEP_NAME", "PROCESS_START_TIME", "PROCESS_END_TIME", "START_QUANTITY", "OUT_QUANTITY", "REJECT_QUANTITY",
"WRWK_FISCAL_YEAR", "WRWK_WORK_WEEK_NO"}),
Filter_Devices= Table.SelectRows(DEVICES, each ([DEPARTMENT] = "TEST1")),
SelectColumns_Devices = Table.SelectColumns(Filter_Devices,{"DEVC_NUMBER", "PCKG_CODE"}),
Filter_AoLots = Table.SelectRows(AO_LOTS, each Text.Contains([DEVC_NUMBER], "MC09XS3400AFK") or Text.Contains([DEVC_NUMBER], "MC09XS3400AFKR2") or Text.Contains([DEVC_NUMBER], "MC10XS3412CHFK") or Text.Contains([DEVC_NUMBER],
"MC10XS3412CHFKR2")),
SelectColumns_AoLots = Table.SelectColumns(Filter_AoLots,{"ALOT_NUMBER", "DEVC_NUMBER", "TRACECODE", "WAFERLOTNUMBER"}),
TableJoin = Table.Join(SelectColumns_AolotHists, "ALOT_NUMBER", Table.PrefixColumns(SelectColumns_AoLots, "AoLots"), "AoLots.ALOT_NUMBER"),
TableJoin1 = Table.Join(TableJoin, "AoLots.DEVC_NUMBER", Table.PrefixColumns(SelectColumns_Devices, "Devices"), "Devices.DEVC_NUMBER")
in
TableJoin1
Could you please give me some hints why it needs so long to process?
Thanks. -
How to build table join query in Jdeveloper
Hi,
Can someone tell me how to build table join query in Jdeveloper's Expression Builder UI?[Is it possible to create a table of contents in Crystal Reports?|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313335333133303330%7D.do]
-
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?
-
3 Table Join with group by and order by clauses
I am porting from MySQL to Oracle 8i. I have a three Table Join in MySQL as follows:
select distinct TO_DAYS(l.listend)-TO_DAYS(NOW()) AS daysLeft, i.minbid, l.listend, i.itemid, i.itemtitle, l.listingid, l.lendstart, l.lendend, l.status, MAX(b.amount) AS curBid, COUNT(b.amount) AS numBids from TBL_ITEMS i, TBL_LISTING l LEFT JOIN TBL_BIDS b ON l.listingid=b.listingid where i.itemid = l.itemid AND l.status='1' AND (TO_DAYS(l.listend)-TO_DAYS(NOW()) >= 0) AND i.catcode LIKE'12__' GROUP BY listingid order by curBid DESC, daysLeft;
It performs an straight join on the first 2 tables (TBL_ITEMS and TBL_LISTING) and a LEFT JOIN between the previous result set and TBL_BIDS. TBL_BIDS uses a group by clause to obtain MAX and COUNT info. This final result set is the sorted (ORDER BY).
I have tried to reconstruct this type of call in Oracle and have failed. Several problems that I have notices: Oracle does not let me pull in additional columns when doing a GROUP BY clause.
(see below for my work around)
I have worked around the problem by creating a TABLE with the group by functionality and doing a straing 3 table join. (NOTE: I cannot create a view because use a LIKE function in the call... view dont have indexes). However, when I try to alias the column that returns DATE subtraction ("l.listend-TRUNC(SYSDATE) daysLeft" OR "l.listend-TRUNC(SYSDATE) dayLeft") I cannot use the LIKE statement.
Here is my question. How do I port the above 3-table MySQL call to Oracle. Why am I having these problems (is it the Oracle optimizer?) and how do I avaopid them in the future.
I really appreciate anyone's input. Thanks,
Inder
WORK AROUND:
FIRST STEP:
"create TABLE BIDSUM as
select l.listingid, COUNT(b.amount) numBids, MAX(b.amount) curBid from TBL_LISTING l, TBL_BIDS b where l.listingid=b.listingid(+) group by (l.listingid);"
NEXT STEP:
select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE), l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12%';
THIS ALSO WORKS (no LIKE):
"select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode='12'";
BUT THIS DOES NOT (alias the DATE arimetic)
select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12__';I am porting from MySQL to Oracle 8i. I have a three Table Join in MySQL as follows:
select distinct TO_DAYS(l.listend)-TO_DAYS(NOW()) AS daysLeft, i.minbid, l.listend, i.itemid, i.itemtitle, l.listingid, l.lendstart, l.lendend, l.status, MAX(b.amount) AS curBid, COUNT(b.amount) AS numBids from TBL_ITEMS i, TBL_LISTING l LEFT JOIN TBL_BIDS b ON l.listingid=b.listingid where i.itemid = l.itemid AND l.status='1' AND (TO_DAYS(l.listend)-TO_DAYS(NOW()) >= 0) AND i.catcode LIKE'12__' GROUP BY listingid order by curBid DESC, daysLeft;
It performs an straight join on the first 2 tables (TBL_ITEMS and TBL_LISTING) and a LEFT JOIN between the previous result set and TBL_BIDS. TBL_BIDS uses a group by clause to obtain MAX and COUNT info. This final result set is the sorted (ORDER BY).
I have tried to reconstruct this type of call in Oracle and have failed. Several problems that I have notices: Oracle does not let me pull in additional columns when doing a GROUP BY clause.
(see below for my work around)
I have worked around the problem by creating a TABLE with the group by functionality and doing a straing 3 table join. (NOTE: I cannot create a view because use a LIKE function in the call... view dont have indexes). However, when I try to alias the column that returns DATE subtraction ("l.listend-TRUNC(SYSDATE) daysLeft" OR "l.listend-TRUNC(SYSDATE) dayLeft") I cannot use the LIKE statement.
Here is my question. How do I port the above 3-table MySQL call to Oracle. Why am I having these problems (is it the Oracle optimizer?) and how do I avaopid them in the future.
I really appreciate anyone's input. Thanks,
Inder
WORK AROUND:
FIRST STEP:
"create TABLE BIDSUM as
select l.listingid, COUNT(b.amount) numBids, MAX(b.amount) curBid from TBL_LISTING l, TBL_BIDS b where l.listingid=b.listingid(+) group by (l.listingid);"
NEXT STEP:
select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE), l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12%';
THIS ALSO WORKS (no LIKE):
"select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode='12'";
BUT THIS DOES NOT (alias the DATE arimetic)
select i.minbid, i.itemtitle, l.lendstart-TRUNC(SYSDATE) daysLeft, l.lendend, l.listingid, l.status, s.numbids, s.curbid from TBL_ITEMS i, TBL_LISTING l, BIDSUM s where l.listingid=s.listingid AND i.itemid=l.itemid AND l.status='1' AND i.catcode LIKE '12__'; -
How expensive is remote db table join?
In performance tuning a sql statement, I have a query join a local table to two remote tables, it took 9 sec to return 6000+ rows. If I copy the two remote tables to local db, it took 700 msec. All joins/indexes are identical. The remote db is in the same box as the local db.I am only asking for general opinion for experience on remote db table join. From explain plan, I already know it's doing next loop index join on the primary key on the two remote db tables. Only one coluum needed from each remote table. Does it look unusual expensive for 6000 primary key join to remote db tables?. 4 sec for each remote table, added up to 8 sec. The rest of processing is minimal.
Maybe you are looking for
-
Could not complete the liquify command because of a disk error
PSE 13 displays the above message when I try to use the Liquify filter. There are no disk errors on my machine. Other Filters (but not all) also fail to open. Any suggestions please.
-
Macbinary file in home directory
Hello, I have noted lately that there is a mac binary file in my home directory, does anyone know what is this for? I did not notice this file a month and half ago. Everything else is ok with my mac but I am very curious about this file. I tried open
-
What is analize table for?
I know it has something to be about statisc or something like that (I am sure now I must look as someone that has no idea about Oracle) so... what is analize table exactly for? does it improve the index or something like that after calcullating how m
-
Acquiring Analog Input from Multiple Channels in Labview
Hello, i am working on a VI where i need to acquire signals from multiple channels in Labview using NI-9129.Initially i want to acquire contineous input signals (voltage and current) and display it on the graph. Having looked at forum and Labview exa
-
I am converting some ingress procedures into PL/SQL and have a situation where based on the results (i.e. rows returned) I execute different code. So I have a v_file_name_found parameter that is defined locally to the procedure. The procedure is pass