This question already has answers here:
Select random row from a sqlite table
(7 answers)
Closed 3 years ago.
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 ;
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;";
Related
This question already has answers here:
It is possible to have a contains search query in firebase? [duplicate]
(2 answers)
Closed 3 years ago.
i want to search from firebase where the name contain that character from search box at any position in the name? any one help me please
just like this
Query firebaseSearchQuery =
myRef.orderByChild("from").contains(searchText);
You cannot perform contains query in firestore, you can only perform equals to query in firestore, if you want to perform contains query you need to integrate with Algolia
This question already has answers here:
Query based on multiple where clauses in Firebase
(8 answers)
Closed 3 years ago.
From below query I get the data in order of timestamp
Query Users = FirebaseDatabase.getInstance.getReference.child("Users").orderbychild("timestamp");
Now all children are ordered by time.
But how do I filter this query by CurrentUserId?
Query CurrentUser = Users.orderbychild("CurrentUserId");
Firebase does not support multiple orderbychild method. What you can do is, first fetch records from Firebase with current user id
Query Users = FirebaseDatabase.getInstance.getReference.child("Users").orderbychild("CurrentUserId");
Then do timestamp sorting at client end.
This question already has answers here:
Sorting dates in sqlite database?
(3 answers)
Closed 6 years ago.
I have stored date in sqlite database as text in this format : '1 Jan 99'.
Now I want to get data from sqlite database in order by date.
Already tried :
SELECT * FROM Table ORDER BY date(dateColumn) DESC
Select * from Table order by datetime(datetimeColumn) DESC
Please Help!!
try the requet SELECT * FROM Table ORDER BY dateColumn
This question already has answers here:
Improve INSERT-per-second performance of SQLite
(12 answers)
Closed 8 years ago.
I am new to Database.
I am tying to insert 22000 word to a sqlite DB but it is taking forever to complete
for (int i=0;i<s.size();i++){
String sql = "INSERT INTO WORD (word) VALUES ("+"'"+s.get(i)+"'"+");";
statement.executeUpdate(sql);
}
Table name is WORD and field name is word(which is a String)
Here s is an arrylist and s.get(i) returns a string... I have made the connection and trying to update
the table.
It is very slow. What am I doing wrong?
Its slow because you are firing 22000 queries to the database. You should insert in batches. That will fix the problem. Even if a single insert takes 10ms total time is like 3.5 minutes!!
A simple insert query with batches of 2 will look like this
"INSERT INTO WORD (word) VALUES ("+"'"+s.get(i)+"'"+"), ("+"'"+s.get(i+1)+"'"+");";
This will reduce the time by half. Now you will have to programatically insert more of these values.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
java PreparedStatement
Can I make the prepared statement
SELECT * FROM STUDENTS WHERE STUDENT_ID IN ?
into
SELECT * FROM STUDENTS WHERE STUDENT_ID IN (1,2,3)
Given that the collection of student ids is a string array.
I think your best solution is going to be generate the in clause dynamically: IN (?,?,?,?) , and then calling preparedStatement.setInt(i + 1, myValues[i]) for each value in your array/collection. The bad news is you will end up with a different preparedStatement for each time you have a different number of values.
See duplicate question: PreparedStatement IN clause alternatives?