Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to write an update query for SQL Server, for example:
UPDATE x
SET Col1 = y.Col1,
Col2 = y.Col2,
Col3 = y.Col3
FROM
Table1 AS x
INNER JOIN
Table2 AS y ON x.ID = y.ID
But I get an error
Error: near "FROM": syntax error"
I saw same syntax in similar answers, but I can't understand why I get the error
Thanx in advance.
Let's try this: I didn't test the code below so, please kindly let me know the result. Thanks
UPDATE x
SET x.Col1 = y.Col1,
x.Col2 = y.Col2,
x.Col3 = y.Col3
FROM
Table1 AS x
INNER JOIN
Table2 AS y ON x.ID = y.ID
Hope it helps.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I use Jupiter notebook with python for using sql so
i have the next error:
': (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE AllPoints > 30000' at line 11")
and
i have this query
query = '''SELECT players.playerID, lastName, SUM(points) AS AllPoints
FROM players
JOIN players_teams
ON players.playerID = players_teams.playerID
GROUP BY lastName, players.playerID
WHERE AllPoints > 30000
'''
puntos = pd.read_sql(query,db)
puntos
I think it is a simple query so I don t know where it is the error.
thanks for helping
You can't use WHERE after GROUP BY but you can use HAVING. Your query should be :
SELECT
players.playerID, lastName, SUM(points) AS AllPoints
FROM
players
INNER JOIN players_teams ON players.playerID = players_teams.playerID
GROUP BY
players.playerID
HAVING SUM(points) > 30000
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have the following SQL Statement, which gives me an error.
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE + STATUS + STATUSDATE = NULL
WHERE UNIT = '231296' AND BMON = '2020114';
What is wrong with that code?
You can update multiple columns like that:
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE = NULL
,STATUS = NULL
,STATUSDATE = NULL
WHERE UNIT = '231296'
AND BMON = '2020114';
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
SELECT
SUM(a.totalsales) AS TotalSale,
SUM(a.cfee) + SUM(b.fee) * (TotalSale <> 0)
FROM
[dbo].[tbl1] AS a
INNER JOIN
[dbo].[tbl2] AS b ON a.[code] = b.[code]
WHERE
a.ID = '1234';
I'm getting this error:
Incorrect syntax near '<'
If you need condition on aggretated result then use HAVING
SELECT SUM(a.totalsales) AS TotalSale,
ISNULL(SUM(a.cfee) + SUM(b.fee)* SUM(a.totalsales),0) tot
FROM [dbo].[tbl1] AS a
INNER JOIN [dbo].[tbl2] AS b
ON a.[code]= b.[code]
WHERE a.ID= '1234'
HAVING SUM(a.totalsales) <>0;
and you can't use column name alias in select clause you must repeat the code
Try this:
SELECT SUM(a.totalsales) AS TotalSale,
(SUM(a.cfee)
+
SUM(b.fee)* SUM(a.totalsales) ) as sm
FROM [dbo].[tbl1] AS a
INNER JOIN [dbo].[tbl2] AS b
ON a.[code]= b.[code]
WHERE a.ID= '1234'
having SUM(a.totalsales)<>0;
I hope it helps
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Please help, I can't see what I did wrong. But I have 2 group by's
SELECT DISTINCT
SalesmanTable.SalesNum,
(SalesmanTable.SalesFName & ' ' & SalesmanTable.SalesLName),
BusinessInfo.BusinessNum,
BusinessInfo.BusinessName,
BusinessInfo.OwnerName
FROM
((SalesmanTable
LEFT JOIN
OrderInfo ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum])
LEFT JOIN
BusinessInfo ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]
WHERE
OrderInfo.Paid = FALSE
GROUP BY
SalesmanTable.SalesNum, BusinessInfo.BusinessNum
GROUP BY
SalesmanTable.SalesNum,
(SalesmanTable.SalesFName & ' ' & SalesmanTable.SalesLName),
BusinessInfo.BusinessNum, BusinessInfo.BusinessName, BusinessInfo.OwnerName;
This is your FROM clause:
FROM ((SalesmanTable LEFT JOIN
OrderInfo
ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum]
) LEFT JOIN
BusinessInfo
ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]
The parentheses do not balance. So:
FROM (SalesmanTable LEFT JOIN
OrderInfo
ON SalesmanTable.[SalesNum] = OrderInfo.[SalesNum]
) LEFT JOIN
BusinessInfo
ON OrderInfo.[BusinessNum] = BusinessInfo.[BusinessNum]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
If I add custom column in select, I get this error:
20018 Invalid column name '2'.
Here is query example
SELECT
[msg].[MessageTo],
[msg].[MessageFrom],
[msg].[SendTime],
[msg].[ReceiveTime],
[msg].[id],
'2' AS source,
[kat].[id] AS [CategoriId],
[kat].[naziv] AS [CategoriName]
FROM
[SMSServer_1].[dbo].[MessageIn] AS [msg]
LEFT JOIN [Tekijanka].[dbo].[crm_poruka] AS [por] ON [por].[fk_poruka] = [msg].[id]
AND [por].[fk_source] = [2]
LEFT JOIN [Tekijanka].[dbo].[crm_kategorije_poruka] AS [kat] ON [kat].[id] = [por].[fk_kategorija]
WHERE
msg.id NOT IN (
SELECT
fk_poruka
FROM
Tekijanka.dbo.crm_poruka
WHERE
fk_status <> 1
)
ORDER BY
[SendTime] DESC
Is there any way to fix it?
The problem is in LEFT JOIN, not in the SELECT section:
AND [por].[fk_source] = [2]
This condition tries to join fk_source and column named [2]. Of course, there's no such column in tables MessageIn and crm_poruka. You have to change this part of the code (remove the condition or change it to AND [por].[fk_source] = 2).