I am trying to execute this query but I am getting the following error:
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 25 Column: 51
The query is:
SELECT egt.education_guarantee_type_id, egt.description, egt.is_available, egy.year_number
FROM mo_education_guarantee_types egt
INNER JOIN mo_education_guarantee_years egy;
What keyword is missing from my query?
You are close but as jarlh said in his comment you need a join condition such as
SELECT egt.education_guarantee_type_id, egt.description, egt.is_available, egy.year_number
FROM mo_education_guarantee_types egt
INNER JOIN mo_education_guarantee_years egy ON egt.SOMEKEY = egy.SOMEKEY;
SOMEKEY here will refer to a field that exists in both tables.
Hope that helps.
Related
I have to run the following UPDATE query into an Oracle database.
UPDATE Appliance
SET Appliance.IdApplianceType =
(
SELECT AT.id
FROM Appliance A INNER JOIN ApplianceType AT
ON UPPER(A.typeName) = UPPER(AT.name)
AND Appliance.id = A.id)
The objective is to find the match between records of Appliance.typeName and ApplianceType.name and set the ApplianceType.id (primary key) in the Appliance.IdApplianceType (FK ApplianceType) (Note: In a 2nd step normalize Appliance table removing Appliance.typeName column and to use IdApplianceType like relation.)
In oracle 12c(and sqlserver 2008+) it works while in version 11g doesn't work.
I report the error below
QL Error: ORA-00904: "APPLIANCE"."ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Any help will be appreciated :)
Thanks
The extra join seems unnecessary. Why not just use this simpler version?
UPDATE Appliance
SET Appliance.IdApplianceType =
(SELECT AT.id
FROM ApplianceType AT
WHERE UPPER(Appliance.typeName) = UPPER(AT.name)
);
Trying to join two tables but am getting an error
SELECT
FROM ods.academic_outcome_pu
INNER JOIN ods.academic_outcome_pu
ON ods.academic_study.academic_period=ods.academic_outcome_pu.academic_period
AND ON ods.academic_study.person_uid=ods.academic_outcome_pu.person_uid
AND ON ods.academic_study.program=ods.academic_outcome_pu.program
Error returned:
ERROR: syntax error at or near "FROM"
LINE 2: FROM ods.academic_outcome_pu
SQL state: 42601
Character: 8
You're trying to join two tables, but repeated the same table in the FROM-list. From the aliases, it seems you have ods.academic_study and ods.academic_outcome_pu tables, and had better using aliases instead of explicitly writing the table names everytime to qualify the columns stated for the join conditions. And keyword ON should be used only once.
Btw, your error raises due to missing columns next to SELECT keyword. ( col[1/2] are just presumed column names which should be replaced by the real column names ) :
SELECT ods.col1, ods.col2, aop.col1, aop.col2
FROM ods.academic_study ast
JOIN ods.academic_outcome_pu aop
ON ast.academic_period = aop.academic_period
AND ast.person_uid = aop.person_uid -- this first "AND" can be replaced by "WHERE" which could be used once also.
AND ast.program = aop.program
So i am trying to delete some rows in a left joined table using the following code in sql:
DELETE gw_svd_prefix_assignment
FROM gw_svd_prefix_assignment svdp
left join assyst_view av
on upper(svdp.user_name) = upper(av.usr_sc)
where upper(av.usr_sc) IS NULL
commit;
but i am getting this error:
Error starting at line : 1 in command -
DELETE gw_svd_prefix_assignment
FROM gw_svd_prefix_assignment svdp
left join assyst_view av
on upper(svdp.user_name) = upper(av.usr_sc)
where upper(av.usr_sc) IS NULL
commit
Error at Command Line : 2 Column : 1
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Oracle does not support that syntax. UPDATE and DELETE only work on one table . . . the FROM clause cannot contain multiple tables.
Instead, put the logic in the WHERE clause:
delete from gw_svd_prefix_assignment svdp
where not exists (select 1
from assyst_view av
where upper(svdp.user_name) = upper(av.usr_sc)
);
So I have the "column ambiguously defined" error in my sql oracle code and I can't figure out why I have the error. I know it means the code can't figure out which of two columns with the same name to use, so I need to use prefixes. But I have prefixes that are all correct. I looked at the other questions on this error message on the site, but can't figure it out.
ORA-00918: kolumn inte entydigt definierad
00918. 00000 - "column ambiguously defined"
*Cause:
*Action:
Error at Line: 4 Column: 5
SELECT KUND.KNR, KUND.FNAMN, KUND.ENAMN
FROM KUND, ORDERRAD, KUNDORDER, KUNDORDER, ARTIKEL, VARUGRUPP
WHERE KUND.KNR = KUNDORDER.KNR
AND KUNDORDER.ORDNR = ORDERRAD.ORDNR
AND ORDERRAD.ARTNR = ARTIKEL.ARTNR
AND ARTIKEL.VGNR = VARUGRUPP.VGNR
AND VARUGRUPP.VGNAMN = 'skäggvård' OR VARUGRUPP.VGNAMN = 'bondgård';
You join the table KUNDORDER twice, so you have to use an alias to help oracle distinguish between them.
But looking at this, most likely you meant to join this table once, and it is a typo.
As a side note: you're using deprecated implicit join notation: it's better to use FROM tablename JOIN table1 ON (...) JOIN table2 ON (...)-notation.
Second side note: it's good practice to always use aliases for your joined tables to improve readability, e.g.: FROM table1 t1 JOIN table2 t2 ON (...)
I am asking this question because I am not getting an error where I expect there should be an error.
Please help me understand under what circumstances this is possible. I have a query:
select foracid,acct_name, schm_code, schm_type from tbaadm.gam where
acid in(select acid from tbaadm.iar);
This query is returning results without throwing any error. I expect invalid identifier
because the table tbaadm.iar does NOT have a field acid.
When I run:
select acid from tbaadm.iar;
I get:
ORA-00904: "ACID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 772 Column: 8
I am using sqldeveloper and oracle 10g. It is kind of Strange to me. Worth to mention though is that there is a field in tbaadm.iar that is an id and so the right Query Should be:
select foracid,acct_name, schm_code, schm_type from tbaadm.gam where
acid in(select entity_id from tbaadm.iar);
What is going on here?
A subquery that's used in an IN clause can reference columns from the outer query, because this is necessary in correlated subqueries. So your WHERE clause is equivalent to:
WHERE acid IN (SELECT tbaadm.gam.acid FROM tbaadm.iar)
An example of a correlated subquery that shows why this is necessary is:
SELECT *
FROM outer_table
WHERE somefield = (SELECT someotherfield
FROM inner_table
WHERE inner_table.id = outer_table.inner_id)
This is the more common use, where the field from the outer table is used in a WHERE clause of the subquery. But SQL isn't picky about where the field from the outer query is used. It can be used anywhere in the subquery that an expression is permitted, which includes the SELECT clause.