SQL UPDATE忽略WHERE(SQL UPDATE ignores WHERE)

我需要一些帮助...

我试图更新一个表连接到另一个表像下一个:

table1 ID_Website | descr | level 100 2 104 2 105 3

另一张桌子:

table2 ID | URL 100 www.google.es 104 www.youtube.es 105 stackoverflow.com

我试图用“descr”列写一些东西

UPDATE table1 JOIN table2 SET descr = 'something' WHERE table1.level = '2' AND table2.URL = 'www.google.es'

但是,它的作用是:

table1 ID_Website | descr | level 100 something 2 104 something 2 105 3

我知道问题在于“JOIN”,因为它没有任何意义。 但我试图写“从”像我在其他职位阅读,它会返回一个语法错误。 在我们创建表时直接连接的两个表,现在sql不允许我们“INNER JOIN”它们(当我们使用SELECT时,不需要做INNER JOIN)。

我不知道如何继续......非常感谢!

I need a bit of help here...

I'm trying to UPDATE a table which is connected to another table like the next ones:

table1 ID_Website | descr | level 100 2 104 2 105 3

And the other table:

table2 ID | URL 100 www.google.es 104 www.youtube.es 105 stackoverflow.com

I tried to write something on "descr" column with

UPDATE table1 JOIN table2 SET descr = 'something' WHERE table1.level = '2' AND table2.URL = 'www.google.es'

But, what it makes, is:

table1 ID_Website | descr | level 100 something 2 104 something 2 105 3

I know that the problem is in that "JOIN", because it makes no sense. But i tried to write "FROM" like i read in other posts and it returns a syntax error. Both tables where joinned directly when we created the tables and now sql doesn't let us to "INNER JOIN" them (when we use a SELECT, there's no need to do INNER JOINs).

I have no idea how to proceed... Thanks a lot!

最满意答案

您错过了JOIN的ON子句:

UPDATE table1 JOIN table2 ON table1.ID_Website = table2.ID -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SET descr = 'something' WHERE table1.level = '2' AND table2.URL = 'www.google.es'

[ SQL小提琴演示 ]

You're missing the ON clause in the JOIN:

UPDATE table1 JOIN table2 ON table1.ID_Website = table2.ID -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SET descr = 'something' WHERE table1.level = '2' AND table2.URL = 'www.google.es'

[SQL Fiddle Demo]

更多推荐