Sqlite中的错误:sqlite3_prepare_v2失败:在IONIC 2中接近\\\“UNION \\\”:语法错误\},\“代码:5}

时间:2022-06-01 17:05:01

I am using sqlite in IONIC 2 to fetch data from chat table but it keeps giving me error at UNION. Here is my query:

我在IONIC 2中使用sqlite从聊天表中获取数据,但它一直在UNION给我错误。这是我的查询:

SELECT a.id, a.timeDate, a.message, fromUser, toUser FROM ((SELECT id, message, fromUser, toUser, toUser AS uid, timeDate FROM chat WHERE fromUser = ?) UNION (SELECT id, message, fromUser, toUser, fromUser AS uid, timeDate FROM chat WHERE toUser = ? )) AS a GROUP BY a.uid ORDER BY a.id DESC , a.uid DESC

I tried with brackets before UNION and without bracket like (query1) UNION (query2) and (query1 UNION query2) but still that’ not working.

我在UNION之前尝试使用括号,没有像(query1)UNION(query2)和(query1 UNION query2)这样的括号,但仍然没有工作。

This query is working fine in mysql with same structured table.

此查询在具有相同结构化表的mysql中正常工作。

How to solve this problem?

如何解决这个问题呢?

1 个解决方案

#1


1  

Subqueries use parentheses, but a compound query is not made up from subqueries, so it must not use parentheses.

子查询使用括号,但复合查询不是由子查询组成的,因此不能使用括号。

In your query, only the subquery in the FROM clause uses parentheses:

在查询中,只有FROM子句中的子查询使用括号:

SELECT ... FROM (SELECT ... UNION SELECT ...) AS a GROUP BY ...

#1


1  

Subqueries use parentheses, but a compound query is not made up from subqueries, so it must not use parentheses.

子查询使用括号,但复合查询不是由子查询组成的,因此不能使用括号。

In your query, only the subquery in the FROM clause uses parentheses:

在查询中,只有FROM子句中的子查询使用括号:

SELECT ... FROM (SELECT ... UNION SELECT ...) AS a GROUP BY ...