Is there any issue to run multi join in access db - sql

I am trying to run this sql statement in access and found Syntax error
Select *
from TableC C INNER JOIN TableE E
on E.TKey = C.TKey
INNER JOIN TableP P on P.TKey = E.TKey AND E.employee_id = '123'
Error:
syntax error(missing operator) in query expression 'E.TKey = C.TKey
INNER JOIN TableP P on P.TKey = E.TKe'

In access you cannot have multiple joins without separating them with parentheses.
Select *
from (TableC C
INNER JOIN TableE E
on E.TKey = C.TKey)
INNER JOIN TableP P
on P.TKey = E.TKey
AND E.employee_id = '123';

Related

SQL inner join multi part identifier could not be bound

I have a stored procedure with a bunch of joins I can not figure out why this is not working - I get an error:
The multi-part identifier "[table.column]" could not be bound.
This is an altered bit of SQL the original is -
dbo.Release
INNER JOIN
dbo.Cartridge
INNER JOIN
dbo.PriceClass AS PriceClass ON dbo.Cartridge.PriceClassId = PriceClass.Id
INNER JOIN
dbo.CartridgeType ON dbo.Cartridge.CartridgeTypeId = dbo.CartridgeType.Id
ON dbo.Release.Id = dbo.Cartridge.ReleaseId
INNER JOIN
dbo.OemSegmentation
INNER JOIN
dbo.OemProduct ON dbo.OemSegmentation.OemProductId = dbo.OemProduct.Id
INNER JOIN
dbo.OemPlatform ON dbo.OemSegmentation.OemPlatformId = dbo.OemPlatform.Id
INNER JOIN
dbo.OemMediaType ON dbo.OemSegmentation.OemMediaTypeId = dbo.OemMediaType.Id
ON dbo.CartridgeType.Id = dbo.OemSegmentation.SupplCartTypeId
OR dbo.CartridgeType.Id = dbo.OemSegmentation.CartridgeTypeId
LEFT OUTER JOIN
dbo.CartridgeCoverage ON dbo.Cartridge.Id = dbo.CartridgeCoverage.CartridgeId
What I am trying to change it to -
dbo.Release
INNER JOIN
dbo.Cartridge
INNER JOIN
dbo.PriceClass AS PriceClass ON dbo.Cartridge.PriceClassId = PriceClass.Id
INNER JOIN
dbo.CartridgeType ON dbo.Cartridge.CartridgeTypeId = dbo.CartridgeType.Id
ON dbo.Release.Id = dbo.Cartridge.ReleaseId
INNER JOIN
dbo.OemProduct ON OemSegmentation.OemProductId = dbo.OemProduct.Id
INNER JOIN
dbo.OemPlatform ON dbo.OemSegmentation.OemPlatformId = dbo.OemPlatform.Id
INNER JOIN
dbo.OemMediaType ON dbo.OemSegmentation.OemMediaTypeId = dbo.OemMediaType.Id
LEFT OUTER JOIN
dbo.CartridgeCoverage ON dbo.Cartridge.Id = dbo.CartridgeCoverage.CartridgeId
The error happens on these lines
INNER JOIN
dbo.OemProduct ON OemSegmentation.OemProductId = dbo.OemProduct.Id
INNER JOIN
dbo.OemPlatform ON dbo.OemSegmentation.OemPlatformId = dbo.OemPlatform.Id
INNER JOIN
dbo.OemMediaType ON dbo.OemSegmentation.OemMediaTypeId = dbo.OemMediaType.Id
Once you have aliased your table, use the alias to use TWO PART names for columns. i.e [TableAlias].[ColumnName]
I belive you have use column namd Id in all your tables commonly, so whenever you are picking Id column just go for [TableName].Id.
It seems you missed join: "INNER JOIN dbo.OemSegmentation"

getting the error in the below oracle query of inner join

I am executing the below query in oracle but I am getting an error on the execution of the below query , Please advise how to overcome from this specially the error come when i add the last clause of where condition in the query
SELECT t.product_name FROM JOBCODE_PROJECT_TYPE_MAPPING p
INNER JOIN AOBCODE_UCT_MAPPING h
ON p.ID = h.jobcode_id
INNER JOIN WISK_UCTS t
ON h.risk_product_id = t.risk_product_id AND p.id = h.jobcode_id;
where p.sp_job_code= 'Add';
Remove second duplicate condition AND p.id = h.jobcode_id; which is irrelevant in the join context:
SELECT t.product_name FROM JOBCODE_PROJECT_TYPE_MAPPING p
INNER JOIN AOBCODE_UCT_MAPPING h
ON p.ID = h.jobcode_id
INNER JOIN WISK_UCTS t
ON h.risk_product_id = t.risk_product_id
where p.sp_job_code= 'Add';

How can I avoid using the NOT IN and the SUBSELECT in the following query

How can I avoid using the NOT IN subselect in this query and also avoid the subselect ?
select idTipoDocumento,idDocumentoTarea
from ArchivosTarea as a
inner join Tarea as b on a.idEstadoTarea=b.idTarea
where b.idTarea = 160
and idDocumentoTarea not in (select idDocumentoTarea
from ArchivosTarea as a
inner join tiposArchivos as b on a.idTipoDocumento = b.idTipoArchivo
inner join documentoSolicitud as c on b.idTipoArchivo = c.Id_tipo_archivo
inner join tarea as d on a.idEstadoTarea=d.idTarea
where d.idTarea = 160)
I know that probably a LEFT JOIN or something like that should do the trick but I have tried that and it does not provide me the same results as this query.
The actual idea is to avoid the SUBSELECT (of the WHERE) and also avoid the NOT IN.
Using left join:
Select A.idTipoDocumento,A.idDocumentoTarea from
(select idTipoDocumento,idDocumentoTarea
from ArchivosTarea as a
inner join Tarea as b on a.idEstadoTarea=b.idTarea
where b.idTarea = 160)A
left outer join
(select idDocumentoTarea from ArchivosTarea as a
inner join tiposArchivos as b on a.idTipoDocumento = b.idTipoArchivo
inner join documentoSolicitud as c on b.idTipoArchivo = c.Id_tipo_archivo
inner join tarea as d on a.idEstadoTarea=d.idTarea
where d.idTarea = 160)B
on A.idDocumentoTarea=B.idDocumentoTarea
where B.idDocumentoTarea is null
It happens that SQL Server has antijoin aka semiminus aka EXCEPTION JOIN. It return rows in the left argument that don't match when joined by the right.
select idTipoDocumento,idDocumentoTarea
from ArchivosTarea as a
inner join Tarea as b on a.idEstadoTarea=b.idTarea
and b.idTarea = 160
exception join (
select idDocumentoTarea
from ArchivosTarea as a
inner join tiposArchivos as b on a.idTipoDocumento = b.idTipoArchivo
inner join documentoSolicitud as c on b.idTipoArchivo = c.Id_tipo_archivo
inner join tarea as d on a.idEstadoTarea=d.idTarea
where d.idTarea = 160)
You can do this with LEFT JOIN. Also using NOT EXISTS.

Sql Not Compiling Error

i have the above SQL query is not compiling somewhere i lost a truck if you please help me locate the error.
SELECT *
FROM tblWarehouse AS W INNER JOIN (((tblTransactionsSC AS T
LEFT JOIN tblCustomer AS C ON T.tracstID = C.cstID)
INNER JOIN (tblTransactionsSubSC AS TS
LEFT JOIN tblWarehouseItem AS WI
ON TS.trswhiID = WI.whiID)
ON T.traID = TS.trstraID)
ON W.wrhID = T.trawrhID)
LEFT JOIN tblTransactionsSC ON tblStockItemAssignment.siaID = tblTransactionsSC.trasiaID
Your JOIN ON clauses are going haywire; try placing them properly like
SELECT w.*
FROM tblWarehouse AS W
INNER JOIN tblTransactionsSC AS T ON W.wrhID = T.trawrhID
LEFT JOIN tblCustomer AS C ON T.tracstID = C.cstID
INNER JOIN tblTransactionsSubSC AS TS ON T.traID = TS.trstraID
LEFT JOIN tblWarehouseItem AS WI ON TS.trswhiID = WI.whiID
LEFT JOIN tblTransactionsSC ON tblStockItemAssignment.siaID = tblTransactionsSC.trasiaID

Why am I getting a syntax error on these joins?

I'm getting the
Syntax error in JOIN operation
error on this query. This suggests that there's a misplaced parenthesis somewhere in the joins, but I can't figure out what's wrong.
select *
from
((ss
left join
sc
on
ss.guid=sc.guid)
left join
mrc
on
format(c.xDate, "yyyymmddHHMMSS")=mrc.xDate)
left join
c
on
sc.cID=c.id
You are getting an error because c is referenced before it is defined:
select *
from ((ss left join
sc
on ss.guid = sc.guid
) left join
mrc
on format(c.xDate, "yyyymmddHHMMSS") = mrc.xDate
----------------^
) left join
c
on sc.cID = c.id
You can fix this by swapping the joins:
select *
from ((ss left join
sc
on ss.guid = sc.guid
) left join
c
on sc.cID = c.id
) left join
mrc
on format(c.xDate, "yyyymmddHHMMSS") = mrc.xDate