MS Access - Syntax error (missing operator) in query expression - sql

SELECT * FROM exclusivity
left join patent on (exclusivity.[Appl_Type]=patent.[Appl_Type] AND exclusivity.[Appl_No]=patent.[Appl_No] AND exclusivity.[Product_No]=patent.[Product_No])
left join products on (exclusivity.[Appl_Type]=products.[Appl_Type] AND exclusivity.[Appl_No]=products.[Appl_No] AND exclusivity.[Product_No]=products.[Product_No]);
The above query gives Syntax error
(missing operator) in query expression 'exclusivity.[Appl_Type]=patent.[Appl_Type] AND exclusivity.[Appl_No]=patent.[Appl_No] AND exclusivity.[Product_No]=patent.[Product_No])
left join products on (exclusivity.[Appl_Type]=products.[Appl_Type] AND exclusivity.[Appl_No]=products.[Appl_No] AND exclusivity.[Product_No]=products.[Product_No]);'
What could be possible reason?

MS Access has weird requirements for parentheses around joins:
SELECT *
FROM (exclusivity left join
patent
on exclusivity.[Appl_Type] = patent.[Appl_Type] AND
exclusivity.[Appl_No] = patent.[Appl_No] AND
exclusivity.[Product_No] = patent.[Product_No]
) left join
products
on exclusivity.[Appl_Type] = products.[Appl_Type] AND
exclusivity.[Appl_No] = products.[Appl_No] AND
exclusivity.[Product_No] = products.[Product_No];

Related

Sql pgadmin confused

The following query gives me a syntax error:
Select
traseu_stud.An,
traseu_stud.CodSpec
from
traseu_stud
where
NumePren = "Popescu W.T. Vasile"
and AnUniv = "2012-2013"
inner join studenti on traseu_stud.matricol = studenti.matricol
inner join persoane on studenti.idPers = persoane.idPers
ERROR: syntax error at or near "inner"
LINE 3: ...Pren="Popescu W.T. Vasile" and AnUniv="2012-2013" inner join...
^
SQL state: 42601
Character: 122
You have to use subquery if you want use filter in this way:
select * from
(
Select traseu_stud.An,traseu_stud.CodSpec,matricol
from traseu_stud
where NumePren='Popescu W.T. Vasile' and AnUniv='2012-2013'
) a
inner join studenti on a.matricol=studenti.matricol
inner join persoane on studenti.idPers=persoane.idPers
otherwise you have to use filter below way
Select traseu_stud.An,traseu_stud.CodSpec from
traseu_stud inner join
studenti on traseu_stud.matricol=studenti.matricol inner join persoane on
studenti.idPers=persoane.idPers
where NumePren='Popescu W.T. Vasile' and AnUniv='2012-2013'
The JOIN go into the from clause.
Additionally: String constants need to be enclose in single quotes, double quotes are for identifiers:
Select
traseu_stud.An,
traseu_stud.CodSpec
from traseu_stud
inner join studenti on traseu_stud.matricol = studenti.matricol
inner join persoane on studenti.idPers = persoane.idPers
where NumePren = 'Popescu W.T. Vasile'
and AnUniv = '2012-2013'
thank you for your help, but I have same errors, I put here the image with tables and what I want to do: What Specialization(Specializare) and in what Study year(AnUniv) it's the Popescu W.T. Vasile in 2012-2013.
https://i.stack.imgur.com/e1iV1.jpg

Join multiple tables in SQL - [Troubleshoot]

So I want to join three (or more) tables to make my life easier in Access.
however, when I add the code:
SELECT * FROM tbl_Inventory i
LEFT JOIN tbl_FlameConditions1 fc1
ON i.ID = fc1.SampleID
LEFT JOIN tbl_SolventComponents1 sc1
ON i.ID = sc1.SampleID;
to my query in Access, it gives me an error message:
"Syntax error (missing operator) in query expression 'i.ID = fc1.SampleID
LEFT JOIN tbl_SolventComponents1 sc1
ON i.ID = sc1.SampleI' ".
And I forgot about the D and ; in the statement intentionally, since this is what Access gives me...
Does anyone know how to fix this? I already tried various different combinations. Also, if I only try to join 2 tables (either one), it works fine with the code I got.
You would need to add parenthesis in Access:
SELECT * FROM (tbl_Inventory i
LEFT JOIN tbl_FlameConditions1 fc1
ON i.ID = fc1.SampleID)
LEFT JOIN tbl_SolventComponents1 sc1
ON i.ID = sc1.SampleID;

MS Access: SQL View error

I'm getting an error when pasting in a raw SQL query into Access's SQL View. I know Access syntax is a bit special but I can't figure out what it's asking for. The error says: Syntax error (missing operator) in query expression '(jobmatl.suffix = job.suffix) AND (job.job = jobmatl.job) INNER ...................... AS ibl ON jobmatl.item = ibl.item AND job.whse = ibl.whse. The error mentions everything in between what I've written.
SELECT
job.job,
job.suffix,
job.job_date,
job.item AS FG,
jobmatl.item,
job.whse,
ibl.sumofqtyonhand,
ibl.whse
FROM
job
INNER JOIN jobmatl ON (jobmatl.suffix = job.suffix) AND (job.job = jobmatl.job)
INNER JOIN (
(SELECT
i.item,
SUM(i.qty_on_hand) AS sumofqtyonhand,
i.whse
FROM
Item_by_Location_LP_ALL AS i
WHERE
i.hold_flag != 1
GROUP BY
i.item,
i.whse
)) AS ibl ON jobmatl.item = ibl.item AND job.whse = ibl.whse
WHERE
(((job.job_date)=Date()-(DatePart("w",Date(),2,1)-1)));
The FROM should look like this for MS Access:
FROM (job INNER JOIN
jobmatl
ON jobmatl.suffix = job.suffix AND job.job = jobmatl.job
) INNER JOIN
(SELECT i.item, SUM(i.qty_on_hand) AS sumofqtyonhand, i.whse
FROM Item_by_Location_LP_ALL AS i
WHERE i.hold_flag <> 1
GROUP BY i.item, i.whse
) AS ibl
ON jobmatl.item = ibl.item AND job.whse = ibl.whse;
MS Access requires extra parentheses for each JOIN. In addition, you have to levels of parentheses -- and I don't know if that is allowed.

Can Derby handle scalar subqueries in SELECT clause?

I'm having trouble getting my query working. Could someone cast an experienced eye on it please? The table structure is simple (2 one-to-many relationships). The query is trying to work out for each sign, how many contributions there are at each unique "PositionLocation".
Sign <- Signifier (f_key sign_oid) <- Contribution (f_key signifier_oid)
I'm getting the following error:
Error: An ON clause associated with a JOIN operator is not valid.
SQLState: 42972
ErrorCode: -1
My query is:
select s.NAME, c.POSITIONLOCATION, count(*) as num_per_locn,
(
select count(*) from APP.CONTRIBUTION c2
inner join APP.SIGNIFIER si2 on si2.OID = c2.SIGNIFIER_OID
inner join APP.SIGN s2 on s2.OID = si2.SIGN_OID
and s2.OID = s.OID
) as num_per_sign
from APP.CONTRIBUTION c
inner join APP.SIGNIFIER si on si.OID = c.SIGNIFIER_OID
inner join APP.SIGN s on s.OID = si.SIGN_OID
group by s.NAME, c.POSITIONLOCATION

correlated sub query

Trying to show customers' vehicles who had an invoice raised in the past 30 days.
I tried this:
select C.*, V.*
from CAR_OWNERSHIP O
join VEHICLE V on v.VEH_ID = O.VEH_ID
join CUSTOMER C on C.CUS_ID = O.CUS_ID
where exists (select null
from INVOICE I
where I.INV_ID = O.INV_ID and
I.INV_DATE >= date() - 30);
Im getting "syntax error in FROM clause"
I have quickly tried a query in access and I get the same error you get but when I change the JOIN to a specific join like LEFT OUTER JOIN or INNER JOIN then that error goes away but it is replaced with another
Syntax error (missing operator) in query expression in
I researched that and found this post which indicates that access requires parentheses when using more than one join
select *
from (CAR_OWNERSHIP O
left outer join CUSTOMER C on C.CUS_ID = O.Cus_ID)
left outer join VEHICLE V on v.VEH_ID = O.VEH_ID
where exists (select null
from INVOICE I
where I.INV_ID = O.INV_ID and
I.INV_DATE >= date() - 30);
I do hope this helps