0

我只想在使用条件时只订购第二条SELECT语句。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+"});

上面的查询是对总 Union 语句进行排序。

谁能告诉我如何仅对第二条SELECT语句进行排序?

4

2 回答 2

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 中合并它们。

于 2013-06-03T13:46:17.967 回答
0

Try isolating the 2nd SELECT with parentheses:

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)
于 2013-06-03T13:36:53.683 回答