2013-06-03 26 views
0

我只想在使用UNION ALL時僅聲明第二個SELECT聲明條件。我寫的查詢爲:如何在android中使用UNION ALL時使用特定語句的命令

db.rawQuery("SELECT _id, product_code, product_name, product_category,discount, in_stock, price, brand 
    FROM ProductDetails 
    WHERE _id || ' ' || product_name || product_code 
    LIKE ? 
    UNION ALL SELECT _id, product_code, product_name, product_category,discount, in_stock, price, brand 
    FROM ProductDetails WHERE _id || ' ' || product_name || product_code 
    NOT LIKE ? ORDER BY brand ", new String[] { "%" +searchValue+ "%","%" +searchValue+"}); 

上面的查詢是對整個聯合聲明進行排序。

任何人可以告訴我如何排序第二SELECT聲明?

回答

0

嘗試用括號隔離的第二選擇:

UNION ALL (SELECT _id, product_code, product_name, product_category,discount, in_stock, price, brand 
    FROM ProductDetails WHERE _id || ' ' || product_name || product_code 
    NOT LIKE ? ORDER BY brand) 
+0

我試過那個但沒用。它給了SQlite異常。 – Charan

1

不知道這在SQLite的工作,但它是值得一試:

SELECT _id, product_code, product_name, product_category,discount, in_stock, price, brand 
FROM ProductDetails 
WHERE _id || ' ' || product_name || product_code 
LIKE ? 
UNION ALL SELECT * FROM (SELECT _id, product_code, product_name, product_category,discount, in_stock, price, brand 
FROM ProductDetails WHERE _id || ' ' || product_name || product_code 
NOT LIKE ? ORDER BY brand) 

如果不工作,你也可以創建兩個單獨的SQL查詢並在java中將它們聯合起來。

+0

我試過這個,但是它沒有排序第二個查詢條目。 – Charan