I
I
Ilushka2014-04-16 11:45:36
SQL
Ilushka, 2014-04-16 11:45:36

How to add a new field with a condition on the old one using SQL?

Hello!
Again there is a task on SQL.
There is a huge DB on clients in Access (more than 5 million records).
Each client has a city.
I have another table in which each city has a region in the adjacent right field.
I would like to add a region to the first table depending on the city (according to the second table)
Can you please tell me how this can be implemented?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Vershinin, 2014-04-16
@WolfdalE

1. Modify the table by adding a new city column, which will contain the city.
alter table %clients_table% add region %field type%
2. Using an update-request, set the value of the region name from the region-to-city correspondence table for each record.
update %clients_table% set region = (select region_name from regions_cities where city = %clients_table%.city)

V
Vladimir, 2014-04-16
@azrail_dev

Didn't see access, but maybe left join will help you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question