2017-11-30 10 views
0

私はこのクエリを持っている:私はこのクエリを実行したい場合はAndroidのあいまいな列名

SELECT users.name, users.surname, users.pin, users.telephone, users.email, table_doctor_type.dr_type, table_doctor_title.dr_title FROM users join table_doctor_type on dr_type=table_doctor_type.id join table_doctor_title on title_id=table_doctor_title.id 

は、私はこのエラーを取得:ここ

Caused by: android.database.sqlite.SQLiteException: ambiguous column name: dr_type (code 1): , while compiling: SELECT users.name, users.surname, users.pin, users.telephone, users.email, table_doctor_type.dr_type, table_doctor_title.dr_title FROM users join table_doctor_type on dr_type=table_doctor_type.id join table_doctor_title on title_id=table_doctor_title.id 

は私のテーブルです:

// TABLE USERS 
private static final String TABLE_USERS = "users"; 
private static final String COLUMN_ID = "_id"; 
private static final String COLUMN_NAME = "name"; 
private static final String COLUMN_SURNAME = "surname"; 
private static final String COLUMN_PIN = "pin"; 
private static final String COLUMN_TITLE = "title"; 
private static final String COLUMN_DR_TYPE= "dr_type"; 
private static final String COLUMN_EMAIL= "email"; 
private static final String COLUMN_TEL= "telephone"; 
private static final String COLUMN_USER_TYPE= "u_type"; 
//TABLE DR TYPE 
private static final String TABLE_DR_TYPE = "table_doctor_type"; 
private static final String DR_TYPE_COLUMN_ID = "id"; 
private static final String DR_TYPE_COLUMN_DR_TYPE = "dr_type"; 
// TABLE DOCTOR_TITLE 
private static final String TABLE_DR_TITLE = "table_doctor_title"; 
private static final String DR_TITLE_COLUMN_ID = "id"; 
private static final String DR_TITLE_COLUMN_DR_TITLE = "dr_title"; 

private static final String CREATE_TABLE_DR_TYPE = "CREATE TABLE " 
     + TABLE_DR_TYPE + "(" 
     + DR_TYPE_COLUMN_ID + " integer primary key, " 
     + DR_TYPE_COLUMN_DR_TYPE + " text not null);"; 

private static final String CREATE_TABLE_DR_TITLE= "CREATE TABLE " 
     + TABLE_DR_TITLE + "(" 
     + DR_TITLE_COLUMN_ID + " integer primary key, " 
     + DR_TITLE_COLUMN_DR_TITLE + " text not null);"; 

private static final String CREATE_TABLE_USER = "CREATE TABLE " 
     + TABLE_USERS + " (" 
     + COLUMN_ID + " integer primary key autoincrement, " 
     + COLUMN_NAME + " text not null, " 
     + COLUMN_SURNAME + " text not null, " 
     + COLUMN_TITLE + " integer, " 
     + COLUMN_DR_TYPE + " integer, " 
     + COLUMN_PIN + " text not null, " 
     + COLUMN_EMAIL + " text not null, " 
     + COLUMN_TEL + " text not null, " 
     + COLUMN_USER_TYPE + " text not null, " 
     + " FOREIGN KEY ("+COLUMN_TITLE+") REFERENCES "+TABLE_DR_TITLE+"("+DR_TITLE_COLUMN_ID+"), " 
     + " FOREIGN KEY ("+COLUMN_DR_TYPE+") REFERENCES "+TABLE_DR_TYPE+"("+DR_TYPE_COLUMN_ID+") " 
     +");"; 

助けてください?

+1

users.dr_type = table_doctor_type.id'にtable_doctor_typeに参加してみ ':だから、など興味のある特定のdr_type列を、含まれているテーブル名とdr_type名前を付けます。 – CommonsWare

+0

それは正しい答えだった、ティムミスター、私は正しいとしてチェックできるようにこれを答えにする –

答えて

0

はあなたのクエリの一部として、あなたが持っている:

join table_doctor_type on dr_type=table_doctor_type.id 

問題は、このクエリの一部である複数のテーブルでdr_type列を持っているということです。

join table_doctor_type on users.dr_type=table_doctor_type.id 
関連する問題