LEFT JOIN error
Hi,
While running this query I get following error In Orcale Forms Developer 10.2.0.2 and DB 10g but when I run same query in SQL Plus it
throws no errors.
Encountered the symbol "LEFT" when expecting one of the following
for group having intersect minus order stat union where connect.
PROCEDURE post_query IS
BEGIN
SELECT /*+ USE_HASH(o,stm) */
NVL(SUM(CASE o.status WHEN 'P' THEN 1 ELSE 0 END),0),
NVL(SUM(CASE o.status WHEN 'E' THEN 1 ELSE 0 END),0),
NVL(SUM(CASE o.status WHEN 'B' THEN 1 ELSE 0 END),0),
NVL(SUM(CASE WHEN o.status IN ('A','U') AND (NVL(o.priority,'1') = '2' OR stm.surcharge_amount != 0) THEN 1 ELSE 0 END),0),
NVL(SUM(CASE WHEN o.status IN ('A','U') AND (NVL(o.priority,'1') != '2' OR stm.surcharge_amount = 0) THEN 1 ELSE 0 END),0)
INTO :ORDER_STATUS.PENDING,
:ORDER_STATUS.ERROR,
:ORDER_STATUS.BACK_ORDER,
:ORDER_STATUS.EXPEDITE,
:ORDER_STATUS.STD_SHIP
FROM orders o
LEFT JOIN shipment_type_methods stm
ON (o.client = stm.client AND o.shipment_class_code = stm.shipment_class_code)
WHERE o.status IN ('B', 'E', 'P', 'A', 'U')
AND (parent_order_id is null
OR (order_type='G'
AND parent_order_id=original_order_number))
AND o.client = :ORDER_STATUS.CLIENT_NUMBER;
END post_query;Please help me to fix it.
Thanks
Sandy
Hi Mathew,
The ugly table aliases aside: What happens when you try to run this query?
Give more info like sample data, desired output, exact error messages...
Rgds,
Guido
Similar Messages
-
Having issues with a left join, getting ORA-00904 error
Ok this is something very similar to what I am facing, but dumbed down. None of these columns or tables names exist in real life (Very paranoid company I work for, understandable though) but the fundamental problem I am having is like below.
Basically I know I could have done something similar to this is MS SQL (Or am I dreaming?). If I am right or wrong I need to know a way around this.
Obviously if you comment out the "CAL.WEEK_SINCE_2005" and "AND CUST.week_since_2005 = CAL.WEEK_SINCE_2005" it would work. But I really need it to display the date as well. So it can be group'ed by week since 2005.
I will be joining other statements to this. I am hoping on doing this in one select statement instead of creating multiple tables as I am now. All the other joined tables will follow a VERY similar layout to this. So something like this is need to obtain the look.
When ran I get the following error.
I look forward to learning what I did wrong and how I can fix it. :)
select ORG.ORGANIZATION_NAME,
CUST.CUST_COUNT,
CAL.WEEK_SINCE_2005
FROM organization ORG,
calendar CAL
LEFT JOIN (
SELECT CAP.CURRENT_STORE,
CALEN.week_since_2005,
count(CAP.inactive_date) CUST_COUNT
FROM CUST_AGREE_PAST CAP,
calendar CALEN
WHERE CAP.active_date is not null
and CAP.inactive_code in ('T')
and CAP.inactive_date between '01-sep-07' and sysdate
and CAP.INACTIVE_DATE = CALEN.CALENDAR_DATE
and CAP.RSN_CODE_ID in (select rsn_code_id from reasons where title in ('FAIL', 'NO CALL'))
GROUP BY CAP.CURRENT_STORE,
CALEN.week_since_2005) CUST
ON PO.CURRENT_STORE = ORG.ORGANIZATION_NAME
AND CUST.week_since_2005 = CAL.WEEK_SINCE_2005Just noticed a problem (there might be others):
FROM organization ORG,
calendar CAL
LEFT JOIN (You cannot do that - you are mixing Oracle and ANSI join syntax. You have to do one or the other:
FROM organization ORG
JOIN calendar CAL on (ORG.col = CAL.col)
LEFT JOIN (....) -
Simple left-join doesn't work. error with: Unknown column
Hi guys,
can anyone assist on this simple query:
SELECT D.* , SUM( TD.debit_amount), SUM(TAP.amount)
FROM debit AS D, transaction_debit AS TD
LEFT JOIN TA_PAYMENTS AS TAP ON D.debit_id=TAP.debit_id
WHERE D.debit_id = TD.debit_id
GROUP BY TD.debit_idThe error message I receive is:
#1054 - Unknown column 'D.debit_id' in 'on clause' I'm trying to relate 3 tables (debit, transactions-debit and ta_payment), some payment may not exist so therefore i use left join.
thanks for any pointersSELECT D.* , SUM( TD.debit_amount), SUM(TAP.amount)
FROM debit AS D, transaction_debit AS TD
LEFT JOIN TA_PAYMENTS AS TAP ON
D.debit_id=TAP.debit_id
WHERE D.debit_id = TD.debit_id
GROUP BY TD.debit_id
I'm trying to relate 3 tables (debit,
transactions-debit and ta_payment), some payment may
not exist so therefore i use left join.You are trying to mix "the older join syntax", with the join condition in the where-clause, with "the new join syntax", with the join condition in the "on-clause", which I think is causing trouble.
How about using only "the new syntax":
SELECT D.* , SUM( TD.debit_amount), SUM(TAP.amount)
FROM debit AS D JOIN transaction_debit AS TD on (D.debit_id = TD.debit_id)
LEFT JOIN TA_PAYMENTS AS TAP ON (D.debit_id=TAP.debit_id)
GROUP BY TD.debit_idDoes that help? -
Hi Everyone,
Can someone pls shed some light on the situation below
I am understanding alot of what Michael and Rod wrote.... with my prev. post of LEFT JOIN and testing for
not null and doing a double Boolean OR etc.
- but- AM NOT understanding why the IS NOT NULL works, without the double boolean OR
Pls help... have to explain what left join means to user tomm. I'm going to demo the query below and
not the one with the double boolean OR bec. maybe too much info to present at one sitting. tx, sandra
=====================
the query below is left joining the STUDENT table to
HOLD table.
The HOLD table - contains rows for students who have holds on their record.
a student can have more than one hold (health, HIPAA, basic life saving course)
BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
1 to many relationship.
Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
me having to code IS NOT NULL twice....
Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
the IS NOT NULL condition.
I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
and how they should create a query. I need to come up with rules.
If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
thx sooo much, Sandra
SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
ORDER BY O100384.NAME ASCHi,
OK, I will try to explain this. When you outer join table B to table A then the rows in table A which do not match any rows in table B will returned with NULL in the columns from the table B.
Oracle uses the syntax ( +) for outer joins. Now if you add another condition using the ( +) syntax (as shown below) the condition will be processed before the table is joined. Therefore if table A does not match any rows in table B which have col2=1 then the row from table A will be returned with NULLs for the table B columns.
SELECT A.col1, B.col1
FROM A, B
WHERE A.col1 = B.col1( +)
AND B.col2( +)=1
Now, if the condition B.col2=1 was used instead then the condition would be processed after the join and therefore the rows from table A that were joined to table B but did not meet the condition would not be returned by the query.
This applies to a WHERE clause and to the HAVING clause, but with one exception. If you use the ( +) within a group function in a HAVING clause then the ( +) will have no affect because the condition must be processed after group by and group by can only be processed after the join. Therefore MAX(B.col2( +)) = 1 is processed after the join even through it uses the ( +) syntax.
You cannot use an OR or an IN with the ( +) syntax because the meaning of the OR in this situation is ambiguous, is the OR done before or after the join. A query with an OR or IN in an outer will fail with an Oracle ORA-01719 error. Discoverer recognises this situation and removes the ( +) so that the error does not occur. However, without the ( +) the conditions are processed after the join.
Using the ( +) with IS NULL, e.g. col2( +) IS NOT NULL works in the same way. You just have to remember that the col2( +) could be NULL as a result of the outer join and therefore if the condition is processed after the query then the IS NOT NULL will remove the outer joined rows.
Hope that is clear.
Rod West -
How can I add left join in the coding
I intend to dynamic add left jion in my java class.
so I write the coding like below:
incident_id = svc_yokyu_id(+)
(Both of them have been selected in the select sentence.)
However, when I run the app, it will throw a sql error.(ora-01416)
then I copy the error sql sentence and try to test it
QRSLT WHERE (incident_id = svc_yokyu_id(+))--this is a error sql sentence.
Finding that if I delete the left join,(+), the sql will run right,
or I modify the sql like
QRSLT WHERE incident_id in (Select svc_yokyu_id from xxfm_srl_sr_jc_relation xssjr where incident_id = xssjr.svc_yokyu_id(+)) , it run right as well.
according to bussiness requestion, I can't write the coding like above,
so, i don't know how to implement it.
and i hope to your advice. thxDoes a hand come out of the screen, grabbing you by the wrist, every time you try?
Just guessing…
Peter -
Left join and where clause with not equal ( ) returns too many rows
Say I have something like this
Table A
=========
Id
OrderNum
Date
StoreName
AddressKey
Table B
========
Id
StreetNumber
City
State
select a.* from [Table A] a
left join [Table B] b on a.AddressKey = b.Id
where a.StoreName <> 'Burger place'
The trouble is that the above query still returns rows that have StoreName = 'Burger place'
One way Ive handled this is to use a table expression, select everything into that, then select from the CTE and apply the filter there. How could you handle it in the same query however?Hi Joe,
Thanks for your notes.
INT SURROGATE PRIMARY KEY provides a small footprint JOIN ON column. Hence performance gain and simple JOIN programming. In the Addresses table, address_id is 4 bytes as opposed to 15 bytes san. Similarly for the Orders table.
INT SURROGATE PRIMARY KEY is a meaningless number which can be duplicated at will in other tables as FOREIGN KEY. Having a meaningful PRIMARY KEY violates the RDBMS basics about avoiding data duplication. If I make CelebrityName (Frank Sinatra)
a PRIMARY KEY, I have to duplicate "Frank Sinatra" as an FK wherever it needed as opposed to duplicating SURROGATE PRIMARY KEY CelebrityID (79) a meaningless number.
This is how we design in SQL Server world.
QUOTE from Wiki: "
Advantages[edit]
Immutability[edit]
Surrogate keys do not change while the row exists. This has the following advantages:
Applications cannot lose their reference to a row in the database (since the identifier never changes).
The primary or natural key data can always be modified, even with databases that do not support cascading updates across related
foreign keys.
Requirement changes[edit]
Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:
An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies
were separate).
In these cases, generally a new attribute must be added to the natural key (for example, an
original_company column). With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.
Some problem domains do not clearly identify a suitable natural key. Surrogate key avoids choosing a natural key that might be incorrect.
Performance[edit]
Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore a non-redundant distribution of keys causes the resulting
b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than
compound keys.
Compatibility[edit]
While using several database application development systems, drivers, and
object-relational mapping systems, such as
Ruby on Rails or
Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.
Uniformity[edit]
When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.
Validation[edit]
It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to "look differently from"
those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic
of the applications themselves, as this would violate the principles of
Database normalization"
LINK: http://en.wikipedia.org/wiki/Surrogate_key
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
hi guys,
please see this query once.
in 3rd left join i am getting error like subqueries not allowed here.
can you help me to reslove this.
SELECT
'20060201'||d.acct_num as user_ref_area,
ind.name_first||' ' ||ind.name_last AS full_name,
PA.ADDR_FIRST_LINE,
PA.CITY_NAME||','||
PA.STATE_ABBR as city_state,
PA.ZIP_CDE AS zip_cde,
CASE WHEN iphr.pho_stat_cde ='G' THEN
'000'||pha.pho_exchg_num||pha.pho_line_num
ELSE '0000000000'
END AS home_phone,
ind.ss_num,
d.activity_date,
d.acct_num
FROM (
select j.acct_num,j.activity_date
from (
select dxr.acct_num,
to_char(o3.o3bfct) as activity_date
from debtp.o3
JOIN debtp.acct_xref dxr
ON o3.o3e5cd = dxr.e5cd
WHERE o3dhce in ('aj','ja','ta')
AND load_dt >=to_date('2006/01/28','yyyy/mm/dd')-- trunc(sysdate-4) --NEED TO USE SYSDATE-4
UNION
select account_number,TO_CHAR(data_date, 'YYYYMMDD') as activitydate
from clctdm.triad_history
where data_date =to_date('2006/01/31','yyyy/mm/dd')--trunc(sysdate-1) --NEED TO USE SYSDATE-1
and delq_coll_ind in ('960','961','962','963')
) j
left join
select ACCT_NUM
from hbivt1.pp_fd_accts FDAI
where FDAI.DATE_activity >='20060102'--to_char(trunc(add_months(sysdate,-1)),'yyyymmdd')
) k
on j.acct_num =k.acct_num
where k.acct_num IS null
) d
JOIN AUTOR3.ACCT_XREF XR --lookup for arr_id_acct values
ON d.acct_num =xr.acct_num
JOIN AUTOR3.ARR_IP_POSTL_REL AIPL --lookup for postl_addr_id
ON AIPL.ARR_ID = XR.ARR_ID_ACCT
and aipl.actv_ind ='0'
join autor3s.indv ind --table with values for FIRSTDATA
on aipl.hi_num =ind.hi_num_indv
Left JOIN AUTOR3s.POSTL_ADDR PA ----table with values for FIRSTDATA
ON aipl.POSTL_ADDR_ID = PA.POSTL_ADDR_ID
left join autor3.ip_pho_rel iphr
on iphr.hi_num =aipl.hi_num and
start_dt_tm =(
select max(iphr2.start_dt_tm) as start_dt_tm from AUTOR3.IP_PHO_REL IPHR2
WHERE iphr2.rank_num='1'
and iphr2.ip_pho_rel_cde='001000'
and iphr2.actv_ind='0'
and iphr2.hi_num =aipl.hi_num
)Oracle only supports outer joins as extended equalities.
You'll have to use the syntax:
FROM PC2KAUDIT,AUDITDETAIL
WHERE
... (other where clause)
AND
PC2KAUDIT.AUDITID = AUDITDETAIL.AUDITID (+)
This will do basically the same thing. Unfortunately there is no common syntax, unless oyu have a fancy ODBC driver, which might do this translation for you.
null -
Wrap a store procedure which include "Left Join"
In 9i, i write a store procedure :
CREATE OR REPLACE PROCEDURE
get_code(STATION_NUM IN VARCHAR2,COMMAND1 OUT VARCHAR2) AS
BEGIN
SELECT A.*, B.XX
FROM A LEFT JOIN B ON A.ID = B.ID
WHERE A.STATION_NUM = STATION_NUM
END;
AND, I wrap this store procedure, it show error message:
PSU(103,1,50,41):Encountered the symbol "LEFT" when expecting one of the following:
, ; for group having intersect minus order start union where
connect
Why i can run this store procedure, but can't wrap it?
my oracle is 9.2.0.1.0Replace Left Join with "," and put "(+)" symbol after A.ID
Regds,
Balaji -
I have a very basic question related to JPA.
I am using dict tables and connecting it to MaxDB.
In my Entity I have a select statement like this,
@NamedQuery (name = "getOperations", query = "SELECT operT.id FROM SII_ARC_Oper operT " +
"LEFT JOIN SII_ARC_Service serviceT " +
"ON operT.sid = serviceT.sid AND " +
"serviceT.duuid =:duuid")
When I call this in my Bean, I get this error,
An error occurred processing the named query >>getOperations<< with the query string >>SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON operT.sid = serviceT.sid AND serviceT.duuid =:duuid<<. The exception text is: line 1: Variable 'SII_ARC_Service' not declared
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON operT.sid = serviceT.sid AND serviceT.duuid =:duuid
^
line 1: unexpected token: serviceT
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN SII_ARC_Service serviceT ON operT.sid = serviceT.sid AND serviceT.duuid =:duuid
I am just wondering how do I declare the u201CSII_ARC_Serviceu201D in my Entity before the Named Query. Or am I not declaring anything else..?
Thanks
Domnic
Edited by: domnic savio on Jul 21, 2008 12:16 PMI have some improvements now although the problem is not solved yet,
I have the JPQL as
// The Named Query
@NamedQuery (name = "getOperations", query = "SELECT oper.id FROM SII_ARC_Oper oper " +
"LEFT JOIN oper.service serviceT " +
"WHERE serviceT.duuid =:duuid")
// The many to one relationship
@Column(name= "SERVICE_TABLE")
@ManyToOne(targetEntity=com.sap.sii.archeiver.SII_ARC_Service.class)
@JoinColumn(referencedColumnName = "SID")
private SII_ARC_Service service;
On calling the NamedQuery and passing a parameter, I get the error,
Errors have occurred during the precompilation of named queries:
An error occurred processing the named query >>getOperations<< with the query string >>SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN operT.service serviceT WHERE serviceT.duuid =:duuid<<. The exception text is: line 1: Path 'opert.service' is not association path.
SELECT operT.id FROM SII_ARC_Oper operT LEFT JOIN operT.service serviceT WHERE serviceT.duuid =:duuid
1) What association path does the compiler refer too !?!.
2) Is the JPQL Querry valid without an ON clause ?!.
anyone has an idea..!?!
thanks in advance
Domnic -
I'm trying to do a multiple join between three tables. Is it somehow possible to do this with this syntax where I only use the keywords LEFT JOIN and ON once?
SELECT
DW_STAR.PA_POSTER_FACT.*
FROM
DW_STAR.PA_POSTER_FACT
LEFT JOIN
DW_STAR.LEVERANDOER_DIM,
DW_STAR.FAKTURAFILER
ON
DW_STAR.PA_POSTER_FACT.LEVERANDOER_DIM = DW_STAR.LEVERANDOER_DIM.DIMENSION_KEY AND
DW_STAR.PA_POSTER_FACT.FAKTURA_BILAGSNUMMER = DW_STAR.FAKTURAFILER.FAKTURA_ID
WHERE
ROWNUM < 10964656 wrote:
Okay. I just thought I've once seen the other syntax. I get the error "user requested cancel of current operation" when using this code:
The error is returned when the user cancel the session as it says. It's not Oracle canceling by itself.
Do you run this query in SQL Plus, TOAD or SQL Developer?
Keep in mind that LEFT JOIN is a query which returns all records from a table even if does not have relation with the other.
In your case, on the first query, all records in dw_star.pa_poster_fact will be returned even if they don't have found corresponding records based on join conditions in tables dw_star.leverandoer_dim and dw_star.fakturafiler.
Is this exactly what you want? Find all records from dw_star.pa_poster_fact even if there are no records in the other tables?
In this case however, because you select only columns from dw_star.pa_poster_fact (pos.*) your query will have the same result as:
SELECT pos.*
FROM
dw_star.pa_poster_fact pos
WHERE ROWNUM < 10;
{code}
I don't understand the need of joining other tables then.
Regards.
Al -
I'm using a left join in a view object but I get ORA-00942 Table or View does not exist.
When I run the SQL Query in SQLDeveloper, it works fine. But when I use it in my ViewObject, I get the error. The Query looks like this (It is more difficult than this, but this is the part that I get the error in)
SELECT LocationHistory.LOCATION_HISTORY_ID,
LocationHistory.CONFIG_ITEM_ID,
LocationHistory.EMPLOYEE_ID,
LocationHistory.STD_LOCATION_ID,
LocationHistory.FROM_DATE,
LocationHistory.DESCRIPTION,
StandardLocation.STANDARD_LOCATION_ID AS STANDARD_LOCATION_ID1,
StandardLocation.NAME,
StandardLocation.DESCRIPTION AS DESCRIPTION1
FROM HSR_LOC_HISTORY LocationHistory
LEFT JOIN HSR_STD_LOCATION StandardLocation
ON LocationHistory.STD_LOCATION_ID = StandardLocation.STANDARD_LOCATION_ID
WHERE STD_LOCATION_ID = 20
Does anyone know what the problem could be? Thanks for the help in advanceHi,
It looks like the VO validation thinks LEFT is a table (table or view does not exist)
try
FROM HSR_LOC_HISTORY LocationHistory,
HSR_STD_LOCATION StandardLocation
WHERE LocationHistory.STD_LOCATION_ID = StandardLocation.STANDARD_LOCATION_ID(+)
AND STD_LOCATION_ID = 20much easier to read and understand particularly if you have multiple outer joins.
Brenden -
How do u write a LEFT JOIN in Oracle Developer Forms 6i?
I have 2 tables:PERSDET and EMP_MEDICAL_LTA
PERSDET has EMP_ID,EMP_NAME n some other fields.
EMP_MEDICAL_LTA has EMP_ID,FIELD1,FIELD2 n some other fields
EMP_ID is the common field between these 2 tables.
My requirement is to display all the EMP_NAME,that is-EMP_NAME which have field1 and field2 entries, as well as EMP_NAME which donot have field1 and field2 entries. I thought of using a LEFT join for this operation. The query I used is as follows:
SELECT PERSDET.emp_id,PERSDET.emp_name,EMP_MEDICAL_LTA.field1,EMP_MEDICAL_LTA.field2 into emp_id,emp_name,m,l FROM
PERSDET LEFT JOIN EMP_MEDICAL_LTA ON PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID
where <some other joining conditions>;
This query worked perfectly fine when I tried it running on the SQL prompt, but when I wrote it in a cursor in Oracle Forms 6i, it gave an error on the LEFT keyword!
Is there any substitute for LEFT JOIN in Oracle Forms 6i???
Please help!
Thanks!hi,
yes it is very much possible. and you query willbe as follows;
SELECT PERSDET.emp_id,PERSDET.emp_name,EMP_MEDICAL_LTA.field1,EMP_MEDICAL_LTA.field2 into emp_id,emp_name,m,l FROM
PERSDET where PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID(+)
where <some other joining conditions>;
yse, you just have to use (+) symble on the side where the join condition is not fullfilled. the 2 possibilites for your qury is PERSDET.emp_id=EMP_MEDICAL_LTA.EMP_ID(+)
PERSDET.emp_id(+)=EMP_MEDICAL_LTA.EMP_ID
you can execute both and suit your self.
MohibMaan. -
select * from ort
bid mid
18083 7
select * from st
tid bid mid act
318 18083 5 20091
318 18083 6 20091
321 18083 7 NULL
318 18083 16 23970
my out put should be
318 18083 6 20091
(basic idea is
In order to do this I wrote the following query. But I am getting the following error ora-01799. How do i fix this?
select ort.bid,st.tid from ort
left join st
on ort.BiD = st.bid
and st.mid in
(select max(MID)
from St
where BID = ort.BID and TID is not null and MID <= ort.MID
and ACT is not null
)May be this will clear up what I am trying to acheive a little better. I truly appreciate all your help. I have enclosed column headings and data items within double quotes and data is enclosd in double-quotes and separated by comma.
SQL> desc ort
"Name" "Null?" "Type"
"BID" "NUMBER"
"MID" "NUMBER"
SQL> desc st
"Name" "Null?" "Type"
"TID" "NUMBER"
"BID" "NUMBER"
"MID" "NUMBER"
"ACT" "NUMBER"
"LTP" "NUMBER(10)"
SQL> select * from ort
2 ;
"BID" "MID"
"18083", "7"
"18083", "6"
"18083", "16"
"18083", "277"
"18083", "117"
SQL> select * from st;
"TID" "BID" "MID" "ACT" "LTP"
"NULL", "18083", "117", "NULL", "246"
"NULL", "18083", "277", "NULL", "246"
"246", "18083", "272", "54998", "246"
"318", "18083", "6", "20091" "NULL"
"321", "18083", "7", "NULL", "NULL"
"318", "18083", "16", "23970", "NULL"
6 rows selected.
SQL> SELECT ort.bid, st.tid, st.mid, st.act
2 FROM ort
3 LEFT OUTER JOIN
4 st
5 ON ort.bid = st.bid
6 AND st.mid IN (SELECT mid
7 FROM myortview);
"BID" "TID" "MID" "ACT"
"18083", "246", "272", "54998"
"18083", "246", "272", "54998"
"18083", "246", "272", "54998"
"18083", "246", "272", "54998"
"18083", "246", "272", "54998"
SQL> -- expected result is
bid tpid ort.mid st. mid
"18083", "246", "277", "272"
"18083", "246", "117", "116"
"18083", "318", "16", "16"
"18083", "318", "6", "6"
"18083", "318", "7", "6" -
Does CFSQL Not Do Left Joins?
Hello. The following syntax works fine inside a
<CFQUERY> statement getting data from an ODBC database (where
JobList and Reported are tables in the datasource named in the
CFQUERY statement):
select * from JobList j left join Reported r on j.job_no =
r.jobno
However, it does not work when embedded inside a
<CFQUERY> statement trying to join two existing queries (i.e.
dbtype = 'QUERY', where JobList and Reported are the names of the
existing queries.
Instead I receive the error message:
Query Of Queries syntax error. Encountered "j.
If I remove the j and r aliases and go with select * from
JobList left join Reported on JobList.job_no = Reported.jobno, I
receive the error message:
Query Of Queries syntax error. Encountered "left
It does not help matters to add the word 'outer' after the
word 'left'.
Should I be using a different syntax, or does CFSQL simply
not do outer joins? The documentation says it does joins, but
provided no examples.
If CFSQL simply cannot to outer joins, am I stuck? The two
tables to be joined ultimately reside in completely different DB's:
FoxPro and SQL Server.
Thanks for your help.Using
joins - Q-of-Q
Using joins
A join operation uses a single SELECT statement to return a
result set from multiple, related tables, typically those with a
primary key - foreign key relationship. There are two SQL clauses
that perform joins:
WHERE clause ColdFusion supports joins through a WHERE
clause.
INNER JOIN and OUTER JOIN ColdFusion
does not support joins through INNER JOIN or OUTER JOIN
clauses.
Note: Query of Queries supports joins between two tables
only.
FYI, you can sometimes accomplish your OUTER JOINs by using
UNIONs as a work around.
Phil -
Select from 2 tables with common key and than left join(unique result)
Hi,
I have 2 tables that have a common id (Customer_id) and I have a third table which contain her key consist of 3 column ( Customer_id , rms_customer_id,billind_tree_id) and have the manager_name field
I am using a left join because not all the customers have a manager.
I need to take only the manager_name field from the left join but the problem is that I am not getting a unique name results because the customer_id is not the primary key(only part of )
so I have use the following :
left join
( select * from ACCOUNT_Manager am where
rms_customer_id <= all (select rms_customer_id from ACCOUNT_Manager am2 where
am2.customer_id = am.customer_id )) am
on c.ID = am.CUSTOMER_ID (C is one of the first 2 tables with the ID as key)
Is there anyway more efficient of doing it ?
ThanksPlease consider the following when you post a question. This would help us help you better
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.
Maybe you are looking for
-
HELP!: JBO-33001 bc4j.xcfg not found against oc4j 9.0.3
I'm using JDev 9.0.2. Make BC4J project and BC4J JSP application. Then I deployed to remote OC4J server. BC4J JSP works on remote OC4J 9.0.2 but fails on remote OC4J 9.0.3 by JBO-33001. Why?? Of course, I set up the BC4J runtime on both version of OC
-
Can a method be an input parameter?
inside ActionPerformed(ActionEvent e) { Object src = e.getSource(); PlcManager.setWaitCursor(this); try{ if(src == getBtnInquiry()){ onActionInquiry(true); saveLogFile(); } catch (Except
-
Monitoring a non-SAP satellite system in Solution Manager
Hi Folks, I have two quick questions. 1.) What is the proper procedure/tool for monitoring a non-NW system in Solution Manager? Should I be able to use sapccmsr and saposcol on these systems? 2.) What is the proper way to connect a non-NW system to
-
I updated iTunes, now it dosen't work
I updated iTunes now i get this error "iTunes cannot run because some of its required files are missing. Please reinstall iTunes." Is it going to count this computer again as another copy of all my songs. This computer is at least two of the 'copies'
-
Achieving tallied Business area wise
HI, Achieving tallied Business area wise trial balance required.Can any body help in this regards.