-1

I want to randomize some values using ID in sqlite query. * am using quiz app and want to randomize our question. In database there is a column for category where category id is used to select proper cat and I want randomize only question with limit *

String query = "select * from quiz where id =" +id ;

1 Answers1

0
SELECT *

Says to select all non-hidden columns from the table. The correct syntax for retrieving specific columns is to code the specific column names (or if there are potential ambiguities tablename.columnname e.g. quiz.question).

So you would want

SELECT question FROM quiz .....

To select a random question, assuming that question is the required column name, then you could use :-

String query = "SELECT question FROM quiz ORDER BY random();";

If you wanted to limit the number of rows returned you could use

String query = "SELECT question FROM quiz ORDER BY random() LIMIT 10;";
MikeT
  • 51,415
  • 16
  • 49
  • 68
  • I tried it but in my database having catagory id I want to display random questions in particular id. – Gaurav Awasthi Aug 15 '19 at 02:16
  • @GauravAwasthi then you need to edit your question to clearly explain your exact requirements with the schema and sample data and the expected results. – MikeT Aug 15 '19 at 02:46