Answer the question
In order to leave comments, you need to log in
How to correctly compose a SQL query (table search)?
There are several tables in one database
number_owner
id, number_table_id, contragents_id
number_table
id, number ....
contragents
id, inn ....
number_table and contragents have data. The number_owner type links these two tables in the database. what sql query should be when i have a separate csv file which has columns:
inn, number
i.e. I eventually need to make an insert into the number_owner table, but at the same time specifying number_table_id, contragents_id, where contragents_id is taken from the inn field, and number_table_id, respectively, from number
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, you already have some lists number in the number_table table, inn in the contragents table and there is a separate list of records in csv that need to be normalized.
IMHO the simplest and most correct solution is to write a small script in any PL.
Depending on the amount of data in existing tables, you can honestly pull them every time, or load them into memory.
1) you need to do a SELECT into the temporary csv content table
2) And then something like
INSERT INTO number_owner(number_table_id,contragent_id)
SELECT nt.id, c.id FROM @tempTable as t
INNER JOIN contragents as c ON t.inn = c.inn
INNER JOIN number_table as nt ON t. number = nt.number
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question