Copy table A column to table B sql

Asked

Viewed 142 times

1

Good afternoon Personal,

I have two tables and I need to make a SELECT to link the code of the cities that are in table B with the cities in table A.

I am using the query:

select
  a.Cidade,
  b.Cidade,
  b.cod
from
  tabelaA a left join tabelaB b on (a.cidade = b.cidade)

Exemplo do que gostaria:

please could help, thank you.

SQL SERVER 2017 Express database

  • 1

    What’s the matter?

  • Hello c3s1, welcome to Sopt! We can help yes. Could you clarify where you are having difficulty? Apparently your select does what you need. It could be more specific with what you expect?

  • @Josédiz - I made a mistake, actually table A has 'N' number of cities, and it repeats several times, and two cities can have the same name in different states, so my query returned a larger amount of records, I solved comparator not only the city, but also the state in which each city belongs, worked out with the above query even, I only added comparison of city by state. Thank you.

1 answer

1

SOLVED !!! Actually table A has 'N' number of cities, and it repeats several times, and two cities can have the same name in different states, so my query returned a larger amount of records, I solved comparator not only the city, but also the state in which each city belongs, worked out with the above query even, I only added comparison of city by state. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.