Android SQLite: How to retrieve data from a table using the id's retrieved from other table

user1846348

I have two tables say

TableA

 ________________________
|ADTMeasurement|ADTid  |
|--------------|-----  | 
|measurement   |1~1~3  |
|measurement   |1~1~12 |
|measurement   |1~1~7  |
|measurement   |1~1~11 |
|measurement   |1~1~99 |
------------------------

TableB

________________________________
|ADTName     |ADTid  |ADTType  |
|------------|-------|---------|
|ADTName_1   |1~1~3  |DTType_1 |
|ADTName_2   |1~1~12 |DTType_2 |
|ADTName_4   |1~1~7  |DTType_3 |
|ADTName_4   |1~1~11 |DTType_4 |
|ADTName_5   |1~1~99 |DTType_5 |
|ADTName_6   |1~1~10 |DTType_3 |
|ADTName_7   |1~1~4  |DTType_4 |
|ADTName_7   |1~1~6  |DTType_5 |
--------------------------------

How do I retrieve selected rows from tableB; for all the "ADTid" from tableA. I need to save the result in a JSONarray so that I can send the it to the server.

Below is the code which I tired to use, which is wrong.

public Cursor getSavedMeasuremnet() {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor mCursor = db.query("SELECT * FROM TableB WHERE ADTId IN (SELECT ADTId FROM TableA WHERE ADTMeasurment = 'measurement'");

        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
    }

I am getting an error msg - cannot resolve method “query(java.lang.string)”

MJM

There is not query method with String only as parameter,you have to pass all the parameter in method as mention below

enter image description here

public JSONArray getSavedMeasuremnet() {
        JSONArray jsonArray=new JSONArray();

        SQLiteDatabase db = this.getWritableDatabase();

        Cursor mCursor = db.rawQuery("SELECT * FROM TableB JOIN TableA ON TableA.ADTid  == TableB.ADTid where TableA.ADTMeasurement='measurement'",null)

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            try {
                    JSONObject jsonObject=new JSONObject();
                    jsonObject.put("ADTName",cursor.getString(cursor.getColumnIndex("ADTName")));
                    jsonObject.put("ADTid",cursor.getString(cursor.getColumnIndex("ADTid")));
                    jsonObject.put("ADTType",cursor.getString(cursor.getColumnIndex("ADTType")));
                    jsonArray.put(jsonObject);
                }  catch (JSONException e) {
                    e.printStackTrace();
                }
            cursor.moveToNext();
        }
        return jsonArray;
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get data from other table using id

From Dev

Codeigniter SQL query : i want to retrieve data from one table using the data from other table

From Dev

SQL: INSERT INTO table(...) VALUES (...) with data retrieved from other tables

From Dev

SQL: INSERT INTO table(...) VALUES (...) with data retrieved from other tables

From Dev

Android SQLite QUERI to retrieve data from Table A if the data is in Table B too

From Dev

How to select the data from a table when it's ability is in an other table?

From Dev

How to edit retrieved data from database and return table's data to the form's text fields

From Dev

how to retrieve all data from joining table using parent key

From Dev

How to retrieve JSON data from MySQL table using PHP?

From Dev

Retrieve array object in a table from another table data id using a where clue in laravel

From Dev

How to show json data in a table format retrieved from node.js server using Angular Js

From Dev

How to retrieve hierarchical data from SQL table

From Dev

How to retrieve data from database table by Username?

From Dev

How to get data from two table in sqlite in android

From Dev

arrange data retrieved from DB in table

From Dev

How to update a field using trigger with data from other table?

From Dev

SQLite select from table based on other table

From Dev

How to retrieve the data from the JTable cell and not the data from the table model?

From Dev

how to use the sqlite query to retrieve the data that i need from three table?

From Dev

Retrieve data from two table

From Dev

retrieve data from pivot table

From Dev

How to order data with matching ID from another table using linq?

From Dev

Take different names from the same column using two different ID's from other table

From Dev

Ordering data from a table with the help of other table by using relationships with laravel?

From Dev

How to insert the values in one table by getting the id from other table

From Dev

How to insert ID from user table to other table

From Dev

Get a data from a different table using id

From Dev

how to insert data from another table with id from my table

From Dev

Filter tuples by using value pairs from other table in SQLite

Related Related

  1. 1

    How to get data from other table using id

  2. 2

    Codeigniter SQL query : i want to retrieve data from one table using the data from other table

  3. 3

    SQL: INSERT INTO table(...) VALUES (...) with data retrieved from other tables

  4. 4

    SQL: INSERT INTO table(...) VALUES (...) with data retrieved from other tables

  5. 5

    Android SQLite QUERI to retrieve data from Table A if the data is in Table B too

  6. 6

    How to select the data from a table when it's ability is in an other table?

  7. 7

    How to edit retrieved data from database and return table's data to the form's text fields

  8. 8

    how to retrieve all data from joining table using parent key

  9. 9

    How to retrieve JSON data from MySQL table using PHP?

  10. 10

    Retrieve array object in a table from another table data id using a where clue in laravel

  11. 11

    How to show json data in a table format retrieved from node.js server using Angular Js

  12. 12

    How to retrieve hierarchical data from SQL table

  13. 13

    How to retrieve data from database table by Username?

  14. 14

    How to get data from two table in sqlite in android

  15. 15

    arrange data retrieved from DB in table

  16. 16

    How to update a field using trigger with data from other table?

  17. 17

    SQLite select from table based on other table

  18. 18

    How to retrieve the data from the JTable cell and not the data from the table model?

  19. 19

    how to use the sqlite query to retrieve the data that i need from three table?

  20. 20

    Retrieve data from two table

  21. 21

    retrieve data from pivot table

  22. 22

    How to order data with matching ID from another table using linq?

  23. 23

    Take different names from the same column using two different ID's from other table

  24. 24

    Ordering data from a table with the help of other table by using relationships with laravel?

  25. 25

    How to insert the values in one table by getting the id from other table

  26. 26

    How to insert ID from user table to other table

  27. 27

    Get a data from a different table using id

  28. 28

    how to insert data from another table with id from my table

  29. 29

    Filter tuples by using value pairs from other table in SQLite

HotTag

Archive