简体   繁体   English

无法使用来自另一个的相应数据正确更新一个MYSQL表

[英]Failing to properly update one MYSQL table with corresponding data from another

Currently, my task is to update the Place1 column in my mkindex table, with the corresponding mkplace_id value in the mkplace table. 目前,我的任务就是在我mkindex表更新PLACE1列,随着mkplace表中相应mkplace_id值。 This seemed simple enough, but I must be misunderstanding something or missing some detail. 这似乎很简单,但是我一定会误会某些东西或缺少一些细节。

The desired result would be storing the corresponding mkplace_id in place of mkindex.Place1 所需的结果将是存储相应的mkplace_id代替mkindex.Place1。

I began by trying variations on this: 我首先尝试对此进行变体:

UPDATE mkindex INNER JOIN mkplace ON mkindex.Place1 = mkplace.mkplace_name SET mkindex.Place1 = mkplace.mkplace_id

This does not have the effect I want it to have. 这没有我想要的效果。 The inner join itself actually matches some of the Place1 = mkplace_name , but absolutely not all expected matches. 内部联接本身实际上匹配一些 Place1 = mkplace_name ,但绝对不是所有预期的匹配。 It returns some 117 matches, out of the hundreds of thousands that it should return, and furthermore it doesn't actually set any rows with mkindex.Place1 to mkplace.mkplace_name . 它返回数十万个匹配中的117个匹配项,此外,它实际上并未mkindex.Place1的任何行设置为mkplace.mkplace_name

This led me to try a few other methods, including: 这使我尝试了其他一些方法,包括:

UPDATE mkindex SET mkindex.Place1 = ( SELECT mkplace_id FROM mkplace WHERE mkindex.Place1 = mkplace.mkplace_name LIMIT 1 )

The number of matches seem to be around the right number, but it just replaces every instance of Place1 with NULL. 匹配数目似乎在正确的数目左右,但是它只是将Place1的每个实例替换为NULL。

Am I overlooking something obvious? 我是否忽略了明显的东西? I also considered it being due to collation, so I have also tried running this before the query: 我也认为这是归因于排序规则的,因此我也尝试在查询之前运行此命令:

ALTER TABLE mkplace CONVERT TO CHARACTER SET latin1 COLLATE latin1_general_ci

Any guidance would be greatly appreciated, I'm more confused than anything at this point. 任何指导将不胜感激,在这一点上,我比任何事物都更加困惑。


mkindex (latin1_general_ci) mkindex latin1_general_ci

mkindex说明


mkplace (utf8_general_ci) mkplace (utf8_general_ci)

mkplace描述

Your first query looks fine, I'm going to go out on a limb and suggest that there may only be 117 rows where mkindex.Place1 is actually equal to mkplace.mkplace_name. 您的第一个查询看起来不错,我打算走出去,建议可能只有117行,其中mkindex.Place1实际上等于mkplace.mkplace_name。 Machines don't lie. 机器不会说谎。 You could add a TRIM() around each column but I doubt that will help. 您可以在每列周围添加一个TRIM(),但是我怀疑这会有所帮助。 To get an idea what you're dealing with try analyzing mkindex first. 为了了解您要处理的内容,请先尝试分析mkindex。

 SELECT mkindex.Place1, COUNT(*) FROM mkindex GROUP BY mkindex.Place1; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM