Sqlite中的錯誤:sqlite3_prepare_v2失敗:在IONIC 2中接近\\\“UNION \\\”:語法錯誤\},\“代碼:5}

[英]Error in Sqlite : sqlite3_prepare_v2 failure: near \\\“UNION\\\” : syntax error\},\"code : 5} in IONIC 2


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 ...

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/07/29/6baf03b97f26dd3c1299f8966f71a19c.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com