Access Syntax Error - sql

I'm attempting to join multiple tables in my Access database. I continue to receive a "syntax error". Please let me know if you need more information. I posted the schema below.
SELECT VicDescriptions.VID,
VicDescriptions.Make,
VicDescriptions.Vic_Year,
VicDescriptions.OptionTable,
VacDescriptions.Accessory,
VacValues.Value,
VacValues.ValueType
FROM VicDescriptions
INNER JOIN VacValues
ON ( VicDescriptions.Vic_Make = VacValues.Vic_Make
AND VicDescriptions.Vic_Year = VacValues.Vic_Year )
INNER JOIN VacDescriptions
ON ( VacDescriptions.Period = VacValues.Period
AND VacDescriptions.VAC = VacValues.VAC);
DATABASE SCHEMA

MS Access like parentheses for joins:
SELECT . . .
FROM (VicDescriptions INNER JOIN
VacValues
ON VicDescriptions.Vic_Make = VacValues.Vic_Make AND
VicDescriptions.Vic_Year = VacValues.Vic_Year
) INNER JOIN
VacDescriptions
ON VacDescriptions.Period = VacValues.Period AND
VacDescriptions.VAC = VacValues.VAC

Related

IN Query Expression . (Error 3075). MS ACESSS

SQL Code: SELECT Alan1, Alan2, Alan3, Alan4, A.A_Ihbar_Sayısı, B.B_Ihbar_Sayısı, C.C_Ihbar_Sayısı FROM A INNER JOIN B ON A.Alan4 = B.Alan4 AND A.Alan3 = B.Alan3 AND A.Alan2 = B.Alan2 INNER JOIN C ON B.Alan4 = C.Alan4 AND B.Alan3 = C.Alan3 AND B.Alan2 = C.Alan2;
I get error in query expression . (Error 3075).I'm sure I didn't make a syntax error. How can I fix this situation?
MS Access has arcane syntax requirements, such as parentheses in the FROM clause for multiple JOINs:
SELECT Alan1, Alan2, Alan3, Alan4, A.A_Ihbar_Sayısı, B.B_Ihbar_Sayısı, C.C_Ihbar_Sayısı FROM (A INNER JOIN
B
ON A.Alan4 = B.Alan4 AND A.Alan3 = B.Alan3 AND A.Alan2 = B.Alan2
) INNER JOIN
C
ON B.Alan4 = C.Alan4 AND B.Alan3 = C.Alan3 AND B.Alan2 = C.Alan2;

How can I solve this Query Error in Access?

I have the next error of syntax in Access
SELECT Maestros.Nombre AS Maestro, Materias.Nombre AS Materia
FROM Maestros
INNER JOIN Maestros_Materias ON Maestros.id = Maestros_Materias.Maestro_id
INNER JOIN Materias ON Materias.id = Maestros_Materias.Materia_id
WHERE Maestros.id = 1;
I don't know what is the error here. Thanks for your answers
In Access, you need nested parentheses to handle multiple JOINs.
This should do it:
SELECT Maestros.Nombre AS Maestro, Materias.Nombre AS Materia
FROM (Maestros
INNER JOIN Maestros_Materias ON Maestros.id = Maestros_Materias.Maestro_id)
INNER JOIN Materias ON Materias.id = Maestros_Materias.Materia_id
WHERE Maestros.id = 1;

How do I fix the syntax of a sub query with joins?

I have the following query:
SELECT tours_atp.NAME_T, today_atp.TOUR, today_atp.ID1, odds_atp.K1, today_atp.ID2, odds_atp.K2
FROM (players_atp INNER JOIN (players_atp AS players_atp_1 INNER JOIN (today_atp INNER JOIN odds_atp ON (today_atp.TOUR = odds_atp.ID_T_O) AND (today_atp.ID1 = odds_atp.ID1_O) AND (today_atp.ID2 = odds_atp.ID2_O) AND (today_atp.ROUND = odds_atp.ID_R_O)) ON players_atp_1.ID_P = today_atp.ID2) ON players_atp.ID_P = today_atp.ID1) INNER JOIN tours_atp ON today_atp.TOUR = tours_atp.ID_T
WHERE (((tours_atp.RANK_T) Between 1 And 4) AND ((today_atp.RESULT)="") AND ((players_atp.NAME_P) Not Like "*/*") AND ((players_atp_1.NAME_P) Not Like "*/*") AND ((odds_atp.ID_B_O)=2))
ORDER BY tours_atp.NAME_T;
I'd like to add a field to this query that provides me with the sum of a field in another table (FS) with a few criteria applied.
I've been able to build a stand alone query to get the sum of FS by ID_T as follows:
SELECT tbl_Ts_base_atp.ID_T, Sum(tbl_Ts_mkv_atp.FS) AS SumOfFS
FROM tbl_Ts_base_atp INNER JOIN tbl_Ts_mkv_atp ON tbl_Ts_base_atp.ID_Ts = tbl_Ts_mkv_atp.ID_Ts
WHERE (((tbl_Ts_base_atp.DATE_T)>Date()-2000 And (tbl_Ts_base_atp.DATE_T)<Date()))
GROUP BY tbl_Ts_base_atp.ID_T, tbl_Ts_mkv_atp.ID_Ts;
I now want to match up the sum of FS from the second query to the records of the first query by ID_T. I realise I need to do this using a sub query. I'm confident using these when there's only one table but I consistently get 'syntax errors' when there are joins.
I simplified the first query down to remove all the WHERE conditions so it was easier for me to try and error check but no luck. I guess the resulting SQL will also be easier for you guys to follow:
SELECT today_atp.TOUR, (SELECT Sum(tbl_Ts_mkv_atp.FS)
FROM tbl_Ts_mkv_atp INNER JOIN (tbl_Ts_base_atp INNER JOIN today_atp ON tbl_Ts_base_atp.ID_T = today_atp.TOUR) ON tbl_Ts_mkv_atp.ID_Ts = tbl_Ts_base_atp.ID_Ts AS tt
WHERE tt.DATE_T>Date()-2000 And tt.DATE_T<Date() AND tt.TOUR=today_atp.TOUR
ORDER BY tt.DATE_T) AS SumOfFS
FROM today_atp
Can you spot where I'm going wrong? My hunch is that the issue is in the FROM line of the sub query but I'm not sure. Thanks in advance.
It's difficult to advise an appropriate solution without knowledge of how the database tables relate to one another, but assuming that I've correctly understood what you are looking to achieve, you might wish to try the following solution:
select
tours_atp.name_t,
today_atp.tour,
today_atp.id1,
odds_atp.k1,
today_atp.id2,
odds_atp.k2,
subq.sumoffs
from
(
(
(
(
today_atp inner join odds_atp on
today_atp.tour = odds_atp.id_t_o and
today_atp.id1 = odds_atp.id1_o and
today_atp.id2 = odds_atp.id2_o and
today_atp.round = odds_atp.id_r_o
)
inner join players_atp as players_atp_1 on
players_atp_1.id_p = today_atp.id2
)
inner join players_atp on
players_atp.id_p = today_atp.id1
)
inner join tours_atp on
today_atp.tour = tours_atp.id_t
)
inner join
(
select
tbl_ts_base_atp.id_t,
sum(tbl_ts_mkv_atp.fs) as sumoffs
from
tbl_ts_base_atp inner join tbl_ts_mkv_atp on
tbl_ts_base_atp.id_ts = tbl_ts_mkv_atp.id_ts
where
tbl_ts_base_atp.date_t > date()-2000 and tbl_ts_base_atp.date_t < date()
group by
tbl_ts_base_atp.id_t
) subq on
tours_atp.tour = subq.id_t
where
(tours_atp.rank_t between 1 and 4) and
today_atp.result = "" and
players_atp.name_p not like "*/*" and
players_atp_1.name_p not like "*/*" and
odds_atp.id_b_o = 2
order by
tours_atp.name_t;

UPDATE query with multiple INNER JOINs (syntax error)

I'm trying to run an update query with multiple join statements in VBA, but I keep getting "missing operator" errors. Same happens when I try to run the SQL in query builder. The SQL is:
UPDATE TBL_DocReview_SingleStudy
INNER JOIN TBL_LOA
ON TBL_LOA.MemberName = TBL_DocReview_SingleStudy.Member
INNER JOIN TBL_STUDY
ON TBL_STUDY.StudyName = TBL_DocReview_SingleStudy.Study
SET TBL_DocReview_SingleStudy.DateLOA2 = TBL_LOA.Status
WHERE TBL_STUDY.CDB = 'B'
Can anyone see what I'm doing wrong?
Try:
UPDATE (TBL_DocReview_SingleStudy
INNER JOIN TBL_LOA
ON TBL_LOA.MemberName = TBL_DocReview_SingleStudy.Member)
INNER JOIN TBL_STUDY
ON TBL_STUDY.StudyName = TBL_DocReview_SingleStudy.Study
SET TBL_DocReview_SingleStudy.DateLOA2 = TBL_LOA.Status
WHERE TBL_STUDY.CDB = 'B'
Try the following:
UPDATE s
SET TBL_DocReview_SingleStudy.DateLOA2 = TBL_LOA.STATUS
FROM TBL_DocReview_SingleStudy S
INNER JOIN TBL_LOA ON TBL_LOA.MemberName = TBL_DocReview_SingleStudy.Member
INNER JOIN TBL_STUDY ON TBL_STUDY.StudyName = TBL_DocReview_SingleStudy.Study
WHERE TBL_STUDY.CDB = 'B'

Select from named query

I have issue with following query in MS Access 2013:
SELECT *
FROM (((
(SELECT Stop.TAGeoID AS TAGeoID,
Trip.TripNo AS TripNo
FROM ((((Trip
INNER JOIN BTStopTimes ON Trip.TripNo = BTStopTimes.TripNumber)
INNER JOIN TripsTxt ON (Trip.TripNo = TripsTxt.trip_id
AND Left(TripsTxt.shape_id, 3) <> 'ELD'))
INNER JOIN PatternDetail ON Trip.PatternID = PatternDetail.PatternID
AND BTStopTimes.Sequence = PatternDetail.StopSortOrder)
INNER JOIN Stop ON Stop.GeoID = PatternDetail.GeoID)) AS t3
LEFT JOIN
(SELECT F10,
F16
FROM PatternStopsRaw
WHERE F16 <> ''
GROUP BY F10,
F16)R ON R.F10 = t3.TAGeoID)
LEFT JOIN Timepoint ON Timepoint.PlaceID = R.F16)
LEFT JOIN
(SELECT *
FROM t3
INNER JOIN TripDetail ON t3.TripNo = TripDetail.TripNo)TripTripDetail ON (Timepoint.TimePointID = TripTripDetail.TimepointID))
It says that there is syntax error
The Microsoft Access database engine cannot find the input table or query t3. Make sure it exists and that its name is spelled correctly
It seems that Access does not allow selecting from the named query in the same query.
Any suggestions?
PS: * are used only for testing purposes, I'll remove them once I have working query.
Yes, it appears that Access does not recognize the [t3] alias at that level. Perhaps you could try creating the query...
SELECT Stop.TAGeoID AS TAGeoID,
Trip.TripNo AS TripNo
FROM ((((Trip
INNER JOIN BTStopTimes ON Trip.TripNo = BTStopTimes.TripNumber)
INNER JOIN TripsTxt ON (Trip.TripNo = TripsTxt.trip_id
AND Left(TripsTxt.shape_id, 3) <> 'ELD'))
INNER JOIN PatternDetail ON Trip.PatternID = PatternDetail.PatternID
AND BTStopTimes.Sequence = PatternDetail.StopSortOrder)
INNER JOIN Stop ON Stop.GeoID = PatternDetail.GeoID)
...as a saved query in Access, name it [t3], and then just reference that in your main query.