本文介绍了如何在Android的使用rawQuery()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL查询像这样

I have a sql query like this

String loadFav = "SELECT _id, title, name, favorite FROM table1 where favorite= 1 " 
    				 + "UNION ALL" 
    		         + "SELECT _id, title, name, favorite FROM table2 where favorite= 1"
    				 ;

    Cursor mCursor = mSQLiteDatabase.rawQuery(loadFav, null);

运行此查询时,我得到了一个错误。它是正确的结构?有人可以帮我吗?

I got an error when run this query. Is it right structure? Can someone help me?

推荐答案

总是通过查看SQL字符串解决 - 而不是code,它构建SQL字符串

Always troubleshoot by looking at the SQL string -- not the code that builds the SQL string!

SELECT _id, title, name, favorite FROM table1 where favorite= 1 UNION ALLSELECT _id, title, name, favorite FROM table2 where favorite= 1

您需要之间有一个空格所有第二 SELECT

You need a space between ALL and the second SELECT.

这篇关于如何在Android的使用rawQuery()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 20:25