The following code works:
SELECT b.AAZ002
FROM
AE02 b
INNER JOIN t_aa10 aa10
ON (aa10.AAA100 = 'AA5515' AND b.AA5515 = aa10.AAA102)
But when I change b to a subquery table, it reports ambigious column error:
SELECT b.AAZ002
FROM
(
select count(1) count1, a.BAZ379 , max(a.AB0111) AB0111, max(a.AA5515) AA5515, max(a.AAE011) AAE011
, max(a.AAE035) AAE035, max(a.AAE036) AAE036, max(a.AAE012) AAE012, max(a.AAE012) AAE012
, max(a.ZA0100) ZA0100
from AE02 a
where a.BAE028 = '1'
group by a.BAZ379
) b
INNER JOIN t_aa10 aa10
ON (aa10.AAA100 = 'AA5515' AND b.AA5515 = aa10.AAA102)
Dbeaver reported these 3 errors:
Description Resource Path Location Type
SQL Error [918] [42000]: ORA-00918: column ambiguously defined
Script-8.sql /General/Scripts Unknown Database Script Problem
SQL Error [933] [42000]: ORA-00933: SQL command not properly ended
Script-8.sql /General/Scripts Unknown Database Script Problem
SQL Error [979] [42000]: ORA-00979: not a GROUP BY expression
Script-8.sql /General/Scripts Unknown Database Script Problem
I have prefix on every column, it should not be ambiguous. What could be the cause?
I have corrected the sql after astentx and YoYo pointed out errors. Here is the corrected sql:
SELECT b.AAZ002
FROM
(
select count(1) count1, a.BAZ379 , max(a.AB0111) AB0111, max(a.AA5515) AA5515, max(a.AAE011) AAE011
, max(a.AAE035) AAE035, max(a.AAE036) AAE036, max(a.AAE012) AAE012, max(AAZ002) AAZ002
, max(a.ZA0100) ZA0100
from AE02 a
where a.BAE028 = '1'
group by a.BAZ379
) b
INNER JOIN t_aa10 aa10
ON (aa10.AAA100 = 'AA5515' AND b.AA5515 = aa10.AAA102)
INNER JOIN AB01 ab
ON ab.ZA0100 = b.ZA0100
Related
My inner query is returning results but I get this error
SQL Error [336397221] [42000]: Dynamic SQL Error; SQL error code =
-104; Invalid command; column NOME was specified multiple times for derived table EX [SQLState:42000, ISC error code:336397221]
Here is my query
select * from ( --this gives error
SELECT t.placa, m.nome, GA.ID_AUDESP, GA.NOME AS GRUPO_AUDESP,
T.VALOR as valor,
T.DT_AQUISICAO,
PS.NOME
FROM PATRIMONIO_TOMBAMENTO T
LEFT JOIN PATRIMONIO_GRUPO_AUDESP GA ON GA.ID_GRUPO_AUDESP = T.ID_GRUPO_AUDESP
LEFT JOIN ESTOQUE_MATERIAL M ON M.ID_MATERIAL = T.ID_MATERIAL
LEFT JOIN PATRIMONIO_SETOR PS ON (T.ID_SETOR = PS.ID_SETOR)
WHERE T.ID_ORGAO = '030000'
AND (T.SITUACAO IN('A') or ( T.SITUACAO = 'B' AND T.DT_BAIXA >'2022-01-31'))
AND (T.DT_REATIVADO IS NULL OR T.DT_REATIVADO<= '2022-01-31' or (T.DT_BAIXA >'2022-01-31'))
AND T.dt_cadastro <= '2022-01-31'
) ex
Your derived table has two columns with the name/alias NOME (m.nome and PS.NOME), and as the error indicates, this is not allowed as a name should occur only once. You need to alias one or both columns so they have unique names, or exclude one of them if it would have the same value. The same was already done for the third occurrence of NOME, GA.NOME.
For example:
select * from (
SELECT t.placa,
m.nome as m_nome,
GA.ID_AUDESP,
GA.NOME AS GRUPO_AUDESP,
T.VALOR as valor,
T.DT_AQUISICAO,
PS.NOME as ps_nome
FROM PATRIMONIO_TOMBAMENTO T
-- ...
I have a query that runs perfectly n SQL server but in Oracle, I get the following error:
ORA-00923: FROM keyword not found where expected
SELECT
MyApps.AppConfigurationId,
MyApps.GUID,
MyApps.AppName,
MyApps.BinaryData,
MyApps.Color1,
MyApps.UserCreatorName,
MyApps.CreatedAt,
MyApps.UserUpdaterName,
MyApps.UpdatedAt,
MyApps.UserPublisherName,
MyApps.LastPublishedAt,
MyApps.AppConfigStateId,
MyApps.AppConfigStateLabel
FROM
(
SELECT
ROW_NUMBER() OVER (
PARTITION BY "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."ID"
ORDER BY LastestPublishInfo."PUBLISHEDAT" DESC
) AS RowNum,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."ID" AS AppConfigurationId,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."GUID",
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."NAME" AS AppName,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPICON1"."BINARYDATA",
"OSADMIN_OSDEV1"."OSUSR_4BQ_COLORPA1"."COLOR1",
UserCreator."NAME" AS UserCreatorName,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."CREATEDAT",
UserUpdater."NAME" AS UserUpdaterName,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."UPDATEDAT",
LastestPublishInfo.PublisherName AS UserPublisherName ,
LastestPublishInfo."PUBLISHEDAT" AS LastPublishedAt,
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."APPCONFIGSTATEID",
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON20"."LABEL" AS AppConfigStateLabel
FROM "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266" JOIN "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON20"
ON ( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."APPCONFIGSTATEID" = "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON20"."ID" AND
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."PARENTAPPCONFIGID" IS NULL AND
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."ISACTIVE" = 1
)
JOIN "OSADMIN_OSDEV1"."OSSYS_USER_T266" UserCreator
ON ( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."CREATEDBY" = UserCreator."ID")
LEFT JOIN "OSADMIN_OSDEV1"."OSSYS_USER_T266" UserUpdater
ON ( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."UPDATEDBY" = UserCreator."ID")
LEFT JOIN "OSADMIN_OSDEV1"."OSUSR_4BQ_COLORPA1"
ON( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."COLORPALETTEID" = "OSADMIN_OSDEV1"."OSUSR_4BQ_COLORPA1"."ID")
LEFT JOIN
(
SELECT "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16"."APPCONFIGURATIONID",
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16"."PUBLISHEDAT",
UserPublisher."NAME" AS PublisherName
FROM "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16" LEFT JOIN "OSADMIN_OSDEV1"."OSSYS_USER_T266" UserPublisher
ON ( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16"."PUBLISHEDBY" = UserPublisher."ID")
WHERE "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16"."PUBLISHEDAT" IS NOT NULL
AND
"OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON16"."ISACTIVE" = 0
) LastestPublishInfo
ON (LastestPublishInfo.AppConfigurationId = "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."ID")
LEFT JOIN "OSADMIN_OSDEV1"."OSUSR_4BQ_APPICON1"
ON( "OSADMIN_OSDEV1"."OSUSR_4BQ_APPICON1"."APPCONFIGURATIONID" = "OSADMIN_OSDEV1"."OSUSR_4BQ_APPCON15_T266"."ID" )
) MyApps
WHERE MyApps.RowNum = 1
ORDER BY
MyApps.UpdatedAt DESC
I already tried to check syntax follow some articles but I'm not able to solve it.
Added " around de the aliases, tried to replace attribute names in the subquery not to match the parent but nothing worked.
Hope you could help me with this since I went to the point I have no clue about what to try next!
Cheers
Using the following web: https://rextester.com/l/oracle_online_compiler
I tryed your SQL and got the same error as you.
I then started simplifing it up to:
SELECT 1 AS RowNum
FROM blah
and still getting the same error.
I think RowNum is a reserved word in Oracle, you can not use it as a field alias.
I'm getting the following error
Error while compiling statement:
FAILED: SemanticException Column episodeid Found in more than one tables/subqueries [SQL State=42000, DB Errorcode=40000]
Would anyone be able to help me reconfigure?
Thanks!
This is the code in question:
select
papid, count(distinct episodeid) as epicount,
episovcountcesarean, sum(episovspendcesarean),
count(claimnumber) as claimcount,
sum(allowedamount) as spend
from
3pdcoe_tc_dm_eoc_nep_peri.star_output_episodes e
join
3pdcoe_tc_dm_eoc_nep_peri.dbo_claimpatientservice cps on cps.episodeidd = e.episodeid
join
3pdcoe_tc_dm_eoc_nep_peri.star_output_aggregate a on a.episodeid = e.episodeid
where
aggtype = 'Window' and agggroup = 'Trigger'
and eeany = 0
and year(episodeend) = '2016'
and episovcountcesarean = 1
group by
papid, episovcountcesarean, episovspendcesarean;
In your select list you must specify your target table
select
papid, count(distinct a.episodeid) as epicount,
episovcountcesarean, sum(episovspendcesarean),
count(claimnumber) as claimcount,
sum(allowedamount) as spend
OR
select
papid, count(distinct e.episodeid) as epicount,
episovcountcesarean, sum(episovspendcesarean),
count(claimnumber) as claimcount,
sum(allowedamount) as spend
I am trying to compare two tables with different columns.
I tried below code but it is giving syntax error
Syntax error:
"Exception thrown by code stage: Syntax error in FROM clause"
SELECT [Sheet1].[ID], [Sheet2].[ID_EXT] from [Sheet1], [Sheet2]
A As (SELECT [Sheet1].[ID], ([Sheet1].[Email] + ';' + [Sheet2].[Long Email]) as email from [Sheet1] inner join [Sheet2]
on [Sheet1].[ID] = FORMAT([Sheet2].[ID_EXT],'00000000000')
WHERE [Sheet2].[Type] = 3 AND UCase [Sheet1].[Email] <> UCase [Sheet2].[Long Email])
B As (SELECT [Sheet1].[ID], ([Sheet1].[Batchcode] + ';' + str([Sheet2].[Code])) as Code from [Sheet1] inner join [Sheet2] on [Sheet1].[ID] = FORMAT([Sheet2].[ID_EXT],'00000000000') WHERE [Sheet2].[Type]= 3 AND [Sheet1].[Batchcode]<>FORMAT([Sheet2].[Code],'0000))
SELECT [A].[ID], [A].[Email], [B].[Batchcode] from [A] Full outer join [A] ON [A].[ID]=[B].[ID_EXT]
Instead of A as (select...) you need , (select ... ) as A.
I getting "Ambiguous column reference"
query :
SELECT stage.acct_nbr
FROM (SELECT *
FROM mem stage
JOIN (SELECT acct_nbr,
corp_ent_cd,
sub_seq_nbr,
mem_nbr,
Max(cdc_src_last_updt_ts) AS cdc_src_last_updt_ts
FROM mem
WHERE file_nm = 'DLTV.FULL.MES3191.D180423'
GROUP BY acct_nbr,
corp_ent_cd,
sub_seq_nbr,
mem_nbr) c
ON c.corp_ent_cd = stage.corp_ent_cd
AND c.acct_nbr = stage.acct_nbr
AND c.sub_seq_nbr = stage.sub_seq_nbr
AND c.mem_nbr = stage.mem_nbr
AND stage.cdc_src_last_updt_ts = c.cdc_src_last_updt_ts
WHERE stage.file_nm = 'DLTV.FULL.MES3191.D180423') stage;
Error Message:
Error: Error while compiling statement: FAILED: SemanticException [Error 10007]: Ambiguous column reference acct_nbr in stage (state=42000,code=10007)
Whereas if I do select * instead of select stage.acct_nbr, it is executing without error.
Could somebody solve my issue?
The problem is on SELECT *.
There are two column at subquery c.acct_nbr ,stage.acct_nbr ,so outer SELECT can't stage.acct_nbr distinguish which colunm you want to get.
So you can choose c.acct_nbr or stage.acct_nbr in your select subquery
You can try this.
SELECT stage.acct_nbr
FROM (SELECT c.acct_nbr
FROM mem stage
JOIN (SELECT acct_nbr,
corp_ent_cd,
sub_seq_nbr,
mem_nbr,
Max(cdc_src_last_updt_ts) AS cdc_src_last_updt_ts
FROM mem
WHERE file_nm = 'DLTV.FULL.MES3191.D180423'
GROUP BY acct_nbr,
corp_ent_cd,
sub_seq_nbr,
mem_nbr) c
ON c.corp_ent_cd = stage.corp_ent_cd
AND c.acct_nbr = stage.acct_nbr
AND c.sub_seq_nbr = stage.sub_seq_nbr
AND c.mem_nbr = stage.mem_nbr
AND stage.cdc_src_last_updt_ts = c.cdc_src_last_updt_ts
WHERE stage.file_nm = 'DLTV.FULL.MES3191.D180423') stage;