How to insert the value of two foreign keys in another table in MySQL?

0

Good day, I have a problem and I would like someone to help me. I have a database in which I am trying to insert in the table dig_item, but this has two foreign keys from the tables dig_pagina and dig_hritem, what I need is to insert as such the value of those foreign keys in their respective fields in the table dig_item, I know how to do any insert and I think this can be with insert into select, but when inserting the value of the foreign keys I have no idea how to do it:

String SSQL = "(INSERT INTO dig_item "
        + "(ItemID,"
        + "HrItem,"
        + "PaginaID,"
        + "OpcionLeida,"
        + "TextoLeido,"
        + "NumeroLeido,"
        + "ConjuntoLeido))"
        + "VALUES (?, ?, ?, ?, ?, ?,)";
    
asked by Letty Lopez 22.06.2018 в 18:49
source

1 answer

0

This was the answer I was looking for :) maybe I could not explain what exactly I wanted, thank you very much to the two people who tried to help

                for (QuestionGroup group : structure.getQuestionGroups()) {                 
                int questionsCount = group.getQuestionsCount();
                for (int i = 0; i < questionsCount; i++) {    

                    String choices = sheet.getChoices(group, i);
                    if (choices != null) {
                        System.out.print(choices);


                    String SSQL = "INSERT INTO dig_item "

                            + "(HrItemID,"
                            + "PaginaID,"
                            + "OpcionLeida) "
                            + "VALUES ((SELECT HRItemID FROM dig_hritem WHERE NoItem = "+ (i+1) +"),"
                            + "(SELECT PaginaID FROM dig_pagina WHERE DigitalizacionID=1),'" + choices +"')";
    
answered by 28.06.2018 в 17:35