I'm using MySQL and H2 Database on my project.
I've got a H2 database with URL jdbc:h2:mem:test
.
This is query what I try to run.
SELECT u.id, u.username, u.profileImageUrl,
if ((SELECT 1 FROM subscribe WHERE fromUserId = 1 AND toUserId = u.id), 1, 0) subscribeState,
if ((1=u.id), 1, 0) equalUserState
FROM walking_around_user u INNER JOIN subscribe s
ON u.id = s.toUserId
WHERE s.fromUserId = 2;
It's OK using MySQL, But when I run my project with H2 I got the following error:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT U.ID, U.USERNAME, U.PROFILEIMAGEURL, IF[*] ((SELECT 1 FROM SUBSCRIBE WHERE FROMUSERID = ? AND TOUSERID = U.ID), 1, 0) SUBSCRIBESTATE, IF ((? = U.ID), 1, 0) EQUALUSERSTATE FROM WALKING_AROUND_USER U INNER JOIN SUBSCRIBE S ON U.ID = S.TOUSERID WHERE S.FROMUSERID = ?"; expected "*, NOT, EXISTS, INTERSECTS, UNIQUE"; SQL statement:
SELECT u.id, u.username, u.profileImageUrl, if ((SELECT 1 FROM subscribe WHERE fromUserId = ? AND toUserId = u.id), 1, 0) subscribeState, if ((? = u.id), 1, 0) equalUserState FROM walking_around_user u INNER JOIN subscribe s ON u.id = s.toUserId WHERE s.fromUserId = ? [42001-200]
I wonder how to use "if" grammar with h2 database.