如果一列匹配,则比较2个SQL表

时间:2015-08-24 20:32:42

标签: mysql compare

所以我有2个MySQL表。

表NPC 表下载列表

我想要的是这个。

If 
NPC.NPCID == DROPLIST.MOBID
THEN
DROPLIST.MOBNAME = NPC.NAME

这是我迄今为止所尝试的内容。

select npcid, name 
from npc
    join droplist on npc.npcid=droplist.mobId
where 
    case 
        when droplist.mobid = npc.npcid THEN droplist.mobname = npc.name
        ELSE ''
    END;

这会返回一些值,但实际上并没有改变或做任何事情。 这是它返回的内容。

+---------+-----------------------------------------+
| npcid   | name                                    |
+---------+-----------------------------------------+
|   40115 | Living Armor                            |
|   40118 | Elder                                   |
|   45012 | Rabbit                                  |
|   45021 | Deer                                    |
|   45029 | Fungus                                  |
|   45032 | Blob                                    |
|   45058 | Wild Boar                               |
|   45077 | Stingray                                |
|   45100 | Betrayer's Skeleton Guardsman           |
|   45119 | Orc Elder                               |
|   45154 | Mermaid                                 |
|   45166 | Jack-O-Lantern                          |
|   45167 | Jack-O-Lantern                          |
|   45194 | Right-Hand Bandit                       |
|   45290 | Bats                                    |
|   45292 | Corrupt Guard                           |
|   45300 | Ancient Apparition                      |
|   45301 | Sin of Sepia                            |
|   45302 | Giant Guardian                          |
|   45318 | Giant                                   |
|   45342 | Mutant Giant Queen Ant                  |
|   45343 | Darkmar                                 |
|   45413 | Diego                                   |
|   45421 | Goblin of Ordeal                        |
|   45504 | Assassin Master                         |
|   45507 | Disciple of Death                       |
|   45618 | Knight Vald                             |
|   45670 | Lastabad Royal Guard                    |
|   45698 | Spirit of Ancient Person                |
|   45699 | Spirit of Ancient Person                |
|   45700 | Spirit of Ancient Person                |
|   45701 | Spirit of Enraged Ancient Person        |
|   45702 | Spirit of Enraged Ancient Person        |
|   45703 | Spirit of Enraged Ancient Person        |
|   45704 | Spirit of Enraged Ancient Person        |
|   45705 | Creation of Varlok                      |
|   45706 | Creation of Varlok                      |
|   45707 | Creation of Varlok                      |
|   45708 | Creation of Varlok                      |
|   45709 | Varlok's Servant                        |
|   45737 | Goblin                                  |
|   45775 | Polluted Deep Flower                    |
|   45782 | Polluted Great Spirit's Dirty Sycophant |
|   45784 | Polluted Great Spirit of Light          |
|   45798 | Iron Golem of Maino Shaman              |
|   45799 | Lava Golem of Maino Shaman              |
|   45800 | Living Armor of Maino Shaman            |
|   45804 | Vakuuk                                  |
|   45813 | Mutant Merman                           |
|   45874 | Mutant Lizardman                        |
|   45875 | Skeletal Pirate Head                    |
|   45876 | Unknown 45876                           |
|   45878 | Spirit of Drake                         |
|   45883 | Ribil                                   |
|   45884 | Dedoff                                  |
|   45885 | Ica                                     |
|   45886 | Toad                                    |
|   45887 | Rodeck                                  |
|   45888 | Atushin                                 |
|   45889 | Toda                                    |
|   45890 | Oum                                     |
|   45912 | Ghost Soldier Full of Resentment        |
|   45913 | Ghost Soldier Full of Resentment        |
|   45916 | General Hamel Full of Resentment        |
|   45935 | Cursed Medusa                           |
|   45941 | Cursed Exorcist Saell                   |
|   46034 | Corrupted Zombie General                |
|   46041 | Soul Devourer                           |
|   46119 | Ice Queen's Bow Guard                   |
|   46120 | Ice Queen's Guard                       |
|   46121 | Thebes Elder                            |
|   46124 | IndiGo's cold                           |
|   46125 | Iron Golem                              |
|   46126 | Lycanthrope                             |
|   46127 | Owlbear                                 |
|   46128 | Snow Tiger                              |
|   46129 | SnowMan                                 |
|   46130 | Snow Man                                |
|   46131 | Ghost                                   |
|   46133 | Ice Golem                               |
|   46134 | Ice Man                                 |
|   46153 | Snowman                                 |
|   46154 | Snowman                                 |
|   46155 | Ice Man                                 |
|   46156 | Iron Golem                              |
|   46157 | Lycanthrope                             |
|   46158 | Owlbear                                 |
|   46159 | Snow Tiger                              |
|   47712 | Giant Drake                             |
|   81043 | Wicked Yeti                             |
|   81067 | Black Knight                            |
|   81070 | Contaminated Orc Archer                 |
|   81071 | Contaminated Orc                        |
|   81072 | Contaminated Orc Warrior                |
|   81073 | Polluted Orc Axe Fighter                |
|   81074 | Contaminated Orc Spearman               |
|   81108 | Zombie                                  |
|   81109 | Skeleton                                |
|   99065 | Peer Ivoire                             |
|  100000 | Halloween Scarecrow                     |
|  100005 | Pajeon                                  |
|  100006 | Coming                                  |
|  100007 | Low vision                              |
|  100008 | Taro                                    |
|  100009 | Horror(??)                              |
|  100010 | Sike                                    |
|  100011 | Namur                                   |
|  100012 | Gogam(??)                               |
|  100013 | Dog radeng(??)                          |
|  100014 | Yourself with                           |
|  100015 | Squid                                   |
|  100016 | Cocoon(??)                              |
|  100017 | Racoon                                  |
|  100019 | Bandit                                  |
|  170832 |                                         |
|  460308 | Corroded zombies                        |
|  777860 | Monster Birthday Cake                   |
| 4037001 | Faust                                   |
| 4037001 | Faust                                   |
| 4037001 | Faust                                   |
| 4037001 | Faust                                   |
| 4037001 | Faust                                   |
| 4038003 | Coombe coma                             |
| 4038005 | Coombe coma                             |
| 4060005 | Fort Phantom of the system              |
| 4060006 | Scorpion's Dreamland                    |
| 4060007 | Ruth Court of Dreamland                 |
| 4060008 | Mega Fantasy(??)                        |
| 4060009 | The Venetian's Phantom Boss             |
| 4060010 | Medusa's Dreamland                      |
| 4060011 | Persephone Persephone's Dreamland       |
| 4060012 | Via Dreamland                           |
| 4060013 | For the spirit of the wind              |
| 4060014 | For water ordinance(??)                 |
| 4060015 | For the spirit of the land              |
| 4060016 | Fire for spirits                        |
| 4070000 | Fiery Burning Warrior                   |
| 4070001 | Fiery Burning Archer                    |
| 4070003 | Fiery Fire Egg                          |
| 4070004 | Fiery Astagio                           |
| 4070005 | Firey Lava Golem                        |
| 4070006 | Fiery Phoenix                           |
| 4070007 | Venetian boss of Helong(??0             |
+---------+-----------------------------------------+
143 rows in set

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您需要使用realloc()

执行realloc()
UPDATE

如果您想在JOIN中没有匹配时清空UPDATE droplist AS d JOIN NPC as n ON n.NPCID = d.MOBID SET d.mobName = n.Name ,请使用mobName

NPC