vendredi 18 décembre 2015

SQLite foreing key to get value from another table

so I hace 3 tables:

proveedor: _id descripcion

almacen: _id descripcion

Cab_ing _id descripcion cod_proveedor cod_almacen FOREIGN KEY(cod_proveedor) REFERENCES proveedores(_id) FOREIGN KEY(cod_almacen) REFERENCES almacenes(_id)

when I execute this query:

                 c = db.rawQuery(
                        " SELECT "
                        + "a."+KEY_ROWID + " AS _id,"
                        + "a.cod_agencia AS cod_agencia" + ","
                        + "a.fecha AS fecha" + ","
                        + "b.descripcion AS cod_proveedor" + ","
                        + "c.descripcion AS cod_almacen" + ","
                        + "a.estado AS estado" + ""
                        + " FROM " 
                        + "cab_ings a, proveedores b, almacenes c" 
                        +" WHERE a.cod_proveedor = b._id AND a.cod_almacen = c._id",null);

it doesn't show anything but WHEN I chance de "b._id" to '0' for example it shows. I dunno why, but I think is the reference problem.

Aucun commentaire:

Enregistrer un commentaire