Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Update value where values from two columns match one column value?

I am trying to update my mysql table (cityTable) with the cityFull value in administrativeTable where the cityCode values match country and city in cityTable.

I believe this statement should work. Only part that I am missing is what to put in the ???? for cityCode. It is a bit complicated as it also has a period (.)

UPDATE cityTable INNER JOIN administrativeTable ON (?????????? = administrativeTable.cityCode) SET cityTable.cityFull = administrativeTable.cityFull;

administrativeTable

+----------+-----------+
| cityCode | cityFull  |
+----------+-----------+
| AU.Melb  | Melbourne |
| NZ.Auck  | Auckland  |
+----------+-----------+

cityTable

+---------+------+-----------+
| country | city | cityFull  |
+---------+------+-----------+
| AU      | Melb |           |
| NZ      | Auck |           |
+---------+------+-----------+

Cheers!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need the function CONCAT():

UPDATE cityTable c
INNER JOIN administrativeTable a 
ON CONCAT(c.country, '.', c.city) = a.cityCode 
SET c.cityFull = a.cityFull;

See the demo.
Results:

| country | city | cityFull  |
| ------- | ---- | --------- |
| AU      | Melb | Melbourne |
| NZ      | Auck | Auckland  |
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda