Hello. There is a need to create a complex query (procedure). No difference. There are 2 key related tables. journal_field_data with the key journal_record_id and Journal_Records with the key id . Also in Journal_Records there is a key JOURNAL_ID and JOURNAL_TABLE_ID . The essence of the task itself is that in the html code there is a table with a table nested in it. I needed to pull some of the fields from the nested table into the main one. In order that I could view the previously entered data, I need to rewrite the old data in the new fields in the database. So far I have figured out how to make 2 samples for the conditions of the final query (procedure). Here is how I do:

 select * from journal_field_data where journal_record_id in (select id from Journal_Records where journal_id = 10286 and journal_table_id = 1001) select * from journal_field_data where journal_record_id in (select id from Journal_Records where journal_id = 10286 and journal_table_id = 1) 

With the first query, I select the data in the nested table as it looked before. And I need part of the records (based on the condition on the FIELD_NAME field) to change journal_record_id to the desired journal_record_id from the second query I journal_record_id . So far, I do not understand how to do it. The algorithm is complicated. What I described can be implemented at all. If so then who knows tell me how this can be done. I would be very grateful if there are examples. Thanks in advance.

  • one
    In SQL, you can do everything. And your question is practically impossible to answer, because it is not clear what and what should be replaced. I can only suspect that journal_record_id should be replaced with the corresponding one (according to unclear criteria) taken from some records with table_id = 1. It is better to give the complete structure of the tables used (and not the free-form text, but the form create table) and a sample of the current data and what should be replaced on the basis of this data - Mike
  • As I understand it, the two requests are "as is" and "as it should." The result of each of them is a set of strings. So far, it is not clear on your question, on what basis it is necessary to match the strings of these queries with each other. - Dmitriy

0