0

I have a query that have INSERT with SELECT :-

    INSERT INTO table2 (column1, column2, column3)
    SELECT column1, column2, column3
    FROM table1
    WHERE condition;

What I need to do is insert custom value for column with the select like this :

    INSERT INTO table2 (column1, column2, column3)
    SELECT column1, column3
    FROM table1
    WHERE condition
    column2 = "DATA";

The column 2 I don't need it to get it from the another table I wont to insert it.

1 Answer 1

2

Select a literal value:

INSERT INTO table2 (column1, column2, column3)
SELECT column1, 'DATA', column3
FROM table1
WHERE condition;

I didn't include any actual Java code, but the change you would need should be straightforward. You can either include the literal in your select, or bind a constant string value to a prepared statement.

Sign up to request clarification or add additional context in comments.

1 Comment

I modified it and put it in java and it did well ! Thanks for the help, I will give you the best answer in a few minutes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.