0

Using JPA, I am trying to fetch data from different tables and to have it in single result list using query:

SELECT x.a, y.b FROM (SELECT * from a) as x, (SELECT * FROM b) as y

However it is throwing an exception:

Caused by: com.sap.sql.sqlparser.CommonSQLParserException: - 1:256 - SQL syntax error: not a table reference
- 1:256 - Intermediate-SQL syntax error: table reference must be a table name
- 1:261 - SQL syntax error: arguments in FROM clause of SELECT must be tables or a JOIN of tables
- 1:423 - SQL syntax error: not a table reference
- 1:423 - Intermediate-SQL syntax error: table reference must be a table name
- 1:527 - SQL syntax error: not a table reference

Please adivse on how to resolve or reconstruct the above query.

lxg
  • 12,375
  • 12
  • 51
  • 73
Vipin
  • 1
  • 1
  • 3
  • Does this work in SQL? If the SQL isn't valid, it won't work in JPA either. Why doesn't just "Select x.a, y.b FROM a x, b y" work for you? What values are you trying to get? – Chris Nov 26 '14 at 21:55
  • Couple of distinct values from a table seperately, here is the complete details: String strQuery = SELECT x.a, y.b FROM (select distinct l.xx as a , h.yy from Table1 l INNER JOIN Table2 h ON l.yy = h.yy where h.zz > ?) as a, select distinct l.xx as b , h.yy from Table1 l INNER JOIN Table2 h ON l.yy = h.yy where h.zz > ?) as b) as y; query = em.createNativeQuery(strQuery, ClassName.class); query.setParameter(1, value); List LResult = query.getResultList(); – Vipin Nov 26 '14 at 22:29

0 Answers0