There are two tables, one table contains the name of the sets, the second key pair = value, and a key matching column for one of the sets. In both tables there is a column containing the value of the activity of the set and the activity of the pair, respectively (is_it_used = 1 (included in the sample) or = 0 (not included in the sample)). Something like this...

Tables

We need a query that would connect two tables and display a list of keys, omitting inactive sets and inactive keys. The SQL query looks something like this:

SELECT keys.key, keys.value FROM set, keys WHERE set._id = keys.set_id AND set.is_it_used = 1 AND keys.is_it_used = 1; 

How to put this question in the application through the method (if this method can be used here at all, of course):

 public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder ); 

Or maybe it can somehow be done differently? tell me who knows.

The application has a ContractClass which associates URIs with tables.

  • one
    Are you sure this is a work request? It seems to me that requests to several tables can only be done through a JOIN , isn't it? You can also of course make a rawQuery ... And about your question, there is a rawQuery method that accepts any request as a String - Vladyslav Matviienko
  • one
    @metalurgus Well, the request is written correctly. In most DBMSs , the from statement is similar to the join - Mike operator
  • You can also write a query like this: select keys.key, keys.value from set, join keys on set._id = keys.set_id where set.is_it_used = 1 and keys.is_it_used = 1; meaning is not in the request, but how to implement this request through androidSDK - Evgeny Kuznetsov
  • one
    @ Yevgeny Kuznetsov, ok, I didn’t know that it was possible ... Now I will make an answer about the text request. - Vladyslav Matviienko
  • one
    @ EvgenyKuznetsov when forming a query for a sample of two tables, here only rawQuery () - ZigZag

1 answer 1

You apparently need a rawQuery method. Example:

  String sqlQuery = "SELECT keys.key, keys.value " + "FROM set, keys " + "WHERE set._id = keys.set_id AND set.is_it_used = 1 AND keys.is_it_used = 1;"; Cursor c = db.rawQuery(sqlQuery, null);