I use h2 database 1.4.195. I am writing a request:
String selectFriends = "SELECT * FROM " + ACCOUNT_TABLE_NAME + " JOIN(SELECT friendId FROM " + FRIENDS_TABLE_NAME + " WHERE accountId = ?) AS tbl ON " + ACCOUNT_TABLE_NAME + ".id = tbl.friendId;"; try (PreparedStatement statement = this.connection.prepareStatement(selectFriends)) { statement.setLong(1, id); try (ResultSet resultSet = statement.executeQuery()) { resAccount.setFriends(createFriends(resultSet)); } } catch (SQLException e) { e.printStackTrace(); } private List<Account> createFriends(ResultSet resultSet) throws SQLException { List<Account> friends = new ArrayList<>(); while (resultSet.next()) { friends.add(createAccountFromResult(resultSet)); } return friends; } The temporary table tbl is underlined at compile time.
