PostgreSQL RIGHT JOIN ERROR: syntax error at or near "RIGHT" - sql

Please tell me what is wrong with that sql ?
SELECT users_map.user_id
FROM users_map
WHERE users_map.service_id = 1
AND users_map.service_user_id = 0
RIGHT OUTER JOIN user_data
ON users_map.user_id = user_data.user_id

WHERE clause should be placed at the end of your query:
SELECT users_map.user_id
FROM users_map
RIGHT OUTER JOIN user_data
ON users_map.user_id = user_data.user_id
WHERE users_map.service_id = 1 AND
users_map.service_user_id = 0

Related

Unknown SQL Syntax Error near Keyword 'left'

I am getting a syntax error "incorrect syntax near the keyword 'left'," but I don't know what I am doing wrong. I am trying to run an update query to set French addresses to 5. What am I missing?
UPDATE
Persons p
left join States s on p.StateID = p.pkState
SET
p.International = 5
WHERE
s.CountryRegionCodeID = 'FR';
The correct syntax in SQL Server uses a FROM clause:
UPDATE p
SET p.International = 5
FROM Persons p JOIN
States s
ON p.StateID = p.pkState
WHERE s.CountryRegionCodeID = 'FR';
Note: I changed the LEFT JOIN to a JOIN. The WHERE clause is turning the outer join into an inner join anyway.

Incorrect syntax near the keyword 'INNER' in sql update INNER JOIN

I tried to update some records by joining two tables. but It gives me some syntax errors.
Please help me to fix this.
UPDATE [GCPurchaseInstalment]
INNER JOIN #Temptable
ON GCPurchaseInstalment.StripeInvoiceId = #Temptable.InID
SET GCPurchaseInstalment.AmountReceived = #AMOUNT_RECEIVED,
GCPurchaseInstalment.PaymentFee = #PAYMENT_FEE,
GCPurchaseInstalment.ReceivedDate = #Temptable.paidDate,
GCPurchaseInstalment.StripeInvoiceId = #Temptable.InID,
GCPurchaseInstalment.IsActive = 0
WHERE GCPurchaseInstalment.GCPurchaseInstalmentId = #GCPurchaseInstalmentId
AND #Temptable.id = #RowCount
The correct syntax in SQL Server uses FROM:
UPDATE pi
SET pi.AmountReceived = #AMOUNT_RECEIVED,
pi.PaymentFee = #PAYMENT_FEE,
pi.ReceivedDate = t.paidDate,
pi.StripeInvoiceId = t.InID,
pi.IsActive = 0
FROM [GCPurchaseInstalment] pi JOIN
#Temptable t
ON pi.StripeInvoiceId = t.InID
WHERE pi.GCPurchaseInstalmentId = #GCPurchaseInstalmentId AND
t.id = #RowCount;
Note that I've also introduced table aliases so the query is easier to write and to read.

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;

SQL Developer Error: Missing IN or OUT Parameter at Index:: 1

I know this question has been asked often already but none of the solutions helped me with my problem. When running the following code I get this error:
Missing IN or OUT Parameter at Index:: 1
SELECT DISTINCT gpn.GP_ID, gpn.anrede, gpn.titel, gpn.nachname, gpn.vorname, TO_CHAR(gpn.geburtsdatum, 'dd.mm.') AS Geburtsdatum, gp.sapnr, gp.fname, NVL(tfu.bez, fu.bez) AS bez,
gk.wert as PersonEmail, adr.STRASSE as FirmaStrasse, ort.PLZ as FirmaPLZ, ort.BEZ AS FirmaOrt
FROM S5_PERSONEN gpn
JOIN pf_personfirma pf ON pf.PERSON_ID = gpn.gp_id
JOIN emf_function emf ON emf.pf_id = pf.pf_id
AND TRUNC(NVL(emf.valid_to, sysdate)) >= TRUNC(sysdate)
JOIN pnf_fabrikat pnf on pnf.pnf_id = emf.pnf_id
JOIN gp_geschaeftspartner gp ON gp.gp_id = pf.firma_id
JOIN gp_geschaeftspartner gp2 ON gp2.gp_id = pf.person_id
JOIN gk_kontakt gk on gk.gp_id = gp2.gp_id
join adr_adresse adr on adr.adr_id = gp.adr_id
join pa_ort ort on ort.ort_id = adr.ort_id
JOIN fu_funktion fu ON emf.FU_ID = fu.FU_ID
LEFT OUTER JOIN TFU_FUNKTION tfu ON tfu.FU_ID = fu.FU_ID
AND tfu.locale_id = ?
WHERE TO_CHAR(gpn.geburtsdatum, 'MM') BETWEEN ? AND ?
AND pnf.PN_ID = ?
AND kontaktart_id = 3
What are those ?s supposed to be?
It seems that you want to use "parameters". If so, you can reference them using
a colon sign + parameter name, e.g. where pfn.pn_id = :par_pn_id or
an ampersand + parameter name, e.g. where pfn.pn_id = &par_pn_id

Using SQL alias statement in SELECT query

I've been trying to get this access query to work, I'm learning to write SQL so I wanted to try using alias's for my table to make it easier to use but for some reason I keep getting errors. Here is my original SQL query
SELECT qryCurrentMonthMtrHis.Utility
,qryCurrentMonthMtrHis.MeterID
,qryLastYearAvgMtrHis.AvgOfUnits AS LYRAvgOfUnits
,qryLastYearMtrHis.Units AS LYRUnits
,qryLastMonthMtrHis.Units AS PrevMonUnits
,qryCurrentMonthMtrHis.Units AS CurrentUnits
,qryLastYearAvgMtrHis.AvgOfTotCost
,qryLastYearMtrHis.TotCost AS LYRTotCost
,qryLastMonthMtrHis.TotCost AS PrevMonTotCost
,qryCurrentMonthMtrHis.TotCost AS CurrentTotCost
FROM qryLastYearMtrHis
RIGHT JOIN (
qryLastYearAvgMtrHis RIGHT JOIN (
qryLastMonthMtrHis RIGHT JOIN qryCurrentMonthMtrHis ON (qryLastMonthMtrHis.Utility = qryCurrentMonthMtrHis.Utility)
AND (qryLastMonthMtrHis.MeterID = qryCurrentMonthMtrHis.MeterID)
) ON (qryLastYearAvgMtrHis.Utility = qryCurrentMonthMtrHis.Utility)
AND (qryLastYearAvgMtrHis.MeterID = qryCurrentMonthMtrHis.MeterID)
) ON (qryLastYearMtrHis.Utility = qryCurrentMonthMtrHis.Utility)
AND (qryLastYearMtrHis.MeterID = qryCurrentMonthMtrHis.MeterID);
And here is the one I'm trying to do with alias
SELECT cm.Utility
,cm.MeterID
,lyra.AvgOfUnits AS LYRAvgOfUnits
,lyr.Units AS LYRUnits
,pm.Units AS PrevMonUnits
,cm.Units AS CurrentUnits
,lyra.AvgOfTotCost
,lyr.TotCost AS LYRTotCost
,pm.TotCost AS PrevMonTotCost
,cm.TotCost AS CurrentTotCost
FROM qrylastYearMtrHis lyr
RIGHT JOIN (
qryLastYearAvgMtrHis lyra RIGHT JOIN (
qryLastMonthMtrHis pm RIGHT JOIN qryCurrentMonthMtrHis cm ON (lyr.Utility = cm.Utility)
AND (pm.MeterID = cm.MeterID)
) ON (lyra.Utility = cm.Utility)
AND (lyra.MeterID = cm.MeterID)
) ON (lyr.Utility = cm.Utility)
AND (lyr.MeterID = cm.MeterID);
When I try to run the second one though, it says "syntax error in join operation" and highlights the "lyr" in lyra.AvgOfUnits. From what I've read online it should be working, so I was wondering if anyone could offer any insight?
You use a wrong alias in a join:
RIGHT JOIN (
qryLastYearAvgMtrHis lyra RIGHT JOIN (
qryLastMonthMtrHis pm RIGHT JOIN qryCurrentMonthMtrHis cm ON (lyr.Utility = cm.Utility)
Must be pm.Utilityinstead of lyr.Utility.
Didn't you use a search&replace?
SELECT cm.Utility, cm.MeterID, lyra.AvgOfUnits AS LYRAvgOfUnits, lyr.Units AS LYRUnits,
pm.Units AS PrevMonUnits, cm.Units AS CurrentUnits, lyra.AvgOfTotCost,
lyr.TotCost AS LYRTotCost, pm.TotCost AS PrevMonTotCost,
cm.TotCost AS CurrentTotCost
FROM qryLastYearMtrHis lyr
RIGHT JOIN (qryLastYearAvgMtrHis lyra
RIGHT JOIN (qryLastMonthMtrHis pm
RIGHT JOIN qryCurrentMonthMtrHis cm ON (pm.Utility = cm.Utility)
AND (pm.MeterID = cm.MeterID))
ON (lyra.Utility = cm.Utility) AND (lyra.MeterID = cm.MeterID))
ON (lyr.Utility = cm.Utility) AND (lyr.MeterID = cm.MeterID);