samedi 10 octobre 2015

Get error in joining three tables in SQLite

How to join three tables in SQLite? I have three tables, one is Info, second is workForce and third is workDetails.

Table Info:id(PK),name,status,date,weather

Table WorkForce: id1(PK), subContractors,noOfPeople,noOfHours

Table WorkDetails:id2(PK),project,workDescription,TableInfo_id(FK) //contains multiple row

Table Info

  ID          NAME        Weather        Date     Status
 ----------  ----------  ----------  ----------  ----------
    1           Paul        Sunny         15/10      MC
    2           Allen       Rainy         15/10      Working

Table WorkForce

ID1          SubContractors   NoOfPeople      NoOfHours
----------  --------------   ----------       ----------
1           AAA                2                 2
2           BBB                3                 1

Table WorkDetails

ID2         Project       WorkDescription        TableInfo_id
----------  ----------     --------------          ----------
1              A               B                       1
2                                                      1
3                                                      1
4                                                      1
5               C               D                      2
6                                                      2
7                                                      2
8                                                      2

Assume the name is Paul, so all the row with ID 1 and TableInfo_id 1 will be retrieved.

Here is what I tried so far

public Cursor readEntry(String name) {

        String selectQuery = ("SELECT Weather,Date,Status,SubContractors,NumberOfPeople,NumberOfHours,TimeIn,TimeOut FROM "+TABLE_INFO+TABLE_WORKFORCE+TABLE_WORKDETAILS+ "WHERE Name= ? AND"+ID=ID1+ "AND"+ID=TableInfo_id);
        Cursor c = database.query(TABLE_INFO,TABLE_WORKFORCE,TABLE_WORKDETAILS,new String[]{id,name,weather,date,status,iD1,subcontractors,numberOfPerson,numberOfHours,id2project,workDescription,TableInfo_id},MyDatabaseHelper.Name+"=?",
                new String[] { String.valueOf(name)}, null, null, null, null,null,null,null,null,null,null,null,null);

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

    }

My code seems like not working..how can I do to achieve this? Thanks

Aucun commentaire:

Enregistrer un commentaire