0

I have this code in Java and i need to insert the result into new table. Is this possible with just editing this query?

  ResultSet result = stat.executeQuery("SELECT artist, COUNT(artist) AS countartist FROM table1 GROUP BY artist ORDER BY countartist DESC;");
3
  • 1
    insert into some_table (col1, col2) select artist ... Commented Nov 12, 2016 at 17:25
  • do i need to create the new table before? Commented Nov 12, 2016 at 17:27
  • You can do that or use create table tab_name as select artist ... Commented Nov 12, 2016 at 17:28

1 Answer 1

1

Try this:

ResultSet result = stat.executeUpdate("CREATE TABLE newtable AS SELECT artist, COUNT(artist) AS countartist FROM table1 GROUP BY artist ORDER BY countartist DESC");

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

4 Comments

"java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "(": syntax error)"
Sorry, I put an extra parentheses. Try it now.
"java.sql.SQLException: query does not return ResultSet" could it be something with my code? previous query is working fine
It's not going to return a result set because it's essentially a command.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.