"SELECT * FROM " + PRO_TABLE + " WHERE "
+ PRO_CATID + "= '" + cat_id + "' " +" AND "+ PRO_CAT + "= '" + cat_name + "' " + " AND "
+ PRO_SUB_CATID + "= '" + subcat_id + "' ORDER BY "+ PRO_PP + " ASC ";
Asked
Active
Viewed 484 times
1

K Neeraj Lal
- 6,768
- 3
- 24
- 33

Rasika Singh
- 17
- 4
-
what problem are you facing ? – IntelliJ Amiya May 18 '17 at 06:23
-
when ever i rum a query data is not coming in sorted order – Rasika Singh May 18 '17 at 06:26
-
15.0 20.0 10.0 20.0 20.0 20.0 20.0 0.0 20.0 0.0 12.99 12.99 12.99 12.99 12.99 12.99 12.99 10.05 12.99 0.0 6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 – Rasika Singh May 18 '17 at 06:26
-
there are the price of product but on the query is not working – Rasika Singh May 18 '17 at 06:27
-
6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 6.99 20 20 20 20 20 20 15 12.99 12.99 12.99 12.99 12.99 12.99 12.99 12.99 10.05 10 0 0 0 getting output in this format – Rasika Singh May 18 '17 at 06:29
-
Update the question with the data you are getting and what you are expecting. – Tigger May 18 '17 at 06:29
-
What is the datatype of `PRO_PP` field? – K Neeraj Lal May 18 '17 at 06:30
-
it is of string type – Rasika Singh May 18 '17 at 06:33
-
@RasikaSingh check my answer – IntelliJ Amiya May 18 '17 at 06:39
-
1Sorting a string type sorts the data in alphabetic order. To sort it as according to value you should use a number type field or use `cast` as @IntelliJAmiya's answer shows. – K Neeraj Lal May 18 '17 at 06:41
1 Answers
2
You should use CAST.
ORDER BY CAST(PRO_PP AS REAL) ASC

IntelliJ Amiya
- 74,896
- 15
- 165
- 198
-
getting syntax error -- "SELECT * FROM " + PRO_TABLE + " WHERE " + PRO_CATID + "= '" + cat_id + "' " +" AND " + PRO_SUB_CATID + "= '" + subcat_id + "' ORDER BY CAST " + PRO_PP + " ASC "; – Rasika Singh May 18 '17 at 06:55
-
-
String query = "SELECT * FROM " + PRO_TABLE + " WHERE " + PRO_CATID + "= '" + cat_id + "' " +" AND " + PRO_SUB_CATID + "= '" + subcat_id + "' ORDER BY CAST " +(PRO_PP + " AS REAL ") + " ASC "; – Rasika Singh May 18 '17 at 07:04
-
-
android.database.sqlite.SQLiteException: near "prices": syntax error (code 1): , while compiling: SELECT * FROM pro_table WHERE category_ids= '118' AND sub_category_ids= '0' ORDER BY CAST prices ASC – Rasika Singh May 18 '17 at 07:05
-
String query = "SELECT * FROM " + PRO_TABLE + " WHERE " + PRO_CATID + "= '" + cat_id + "' " +" AND " + PRO_SUB_CATID + "= '" + subcat_id + "' ORDER BY CAST " +(PRO_PP + " AS DOUBLE ") + " DESC "; – Rasika Singh May 18 '17 at 07:10
-
-
-
-
-
near "prices": syntax error (code 1): , while compiling: SELECT * FROM pro_table WHERE category_ids= '118' AND sub_category_ids= '0' ORDER BY CAST prices AS DOUBLE ASC – Rasika Singh May 18 '17 at 07:14
-
near "prices": syntax error (code 1): , while compiling: SELECT * FROM pro_table WHERE category_ids= '118' AND sub_category_ids= '0' ORDER BY CAST prices AS DOUBLE DESC – Rasika Singh May 18 '17 at 07:14
-
2@RasikaSingh `"' ORDER BY CAST(" + PRO_PP + " AS DOUBLE) DESC ";` – K Neeraj Lal May 18 '17 at 07:16