这是代码。有人可以解释一下gi和ogi在此声明中的含义吗?
UPDATE `oceansne_website08`.`oc_gallery_image_description` ogi
LEFT Join `gallery_image_to_album` gi ON gi.image_id = ogi.gallery_image_id
SET
`gallery_album_id` = gi.album_id
WHERE ogi.gallery_album_id =0;
答案 0 :(得分:0)
它是一个别名;在您的示例中引用表的简化形式。
UPDATE `oceansne_website08`.`oc_gallery_image_description` ogi
LEFT JOIN `gallery_image_to_album` gi
ON gi.image_id = ogi.gallery_image_id
SET `gallery_album_id` = gi.album_id
WHERE ogi.gallery_album_id =0
此处ogi引用了表-> oceansne_website08
。oc_gallery_image_description
gi指向表格-> gallery_image_to_album
答案 1 :(得分:0)
让我们说您有一个名为MyVeryLongTableNameThatIFindTediousToWrite
的表,并且您希望将其连接到MyEvenLongerAndMoreTediousTableWithAnEvenLongerName
您可以写:
SELECT * FROM mydb.MyVeryLongTableNameThatIFindTediousToWrite
INNER JOIN myotherdb.MyEvenLongerAndMoreTediousTableWithAnEvenLongerName
ON mydb.MyVeryLongTableNameThatIFindTediousToWrite.id = myotherdb.MyEvenLongerAndMoreTediousTableWithAnEvenLongerName.otherId
WHERE myotherdb.MyEvenLongerAndMoreTediousTableWithAnEvenLongerName.value > 100
要使其更清晰易懂,您可以使用别名,因此相同的选择可以写为:
SELECT * FROM mydb.MyVeryLongTableNameThatIFindTediousToWrite tbla
INNER JOIN myotherdb.MyEvenLongerAndMoreTediousTableWithAnEvenLongerName tblb
ON tbla.id = tblb.otherId
WHERE tblb.value > 100
在某些SQL风格中,您需要编写mydb.MyVeryLongTableNameThatIFindTediousToWrite AS tbla
来代替,但这对于此答案来说有点题外话了