私は4つのテーブルを持つデータベースを持っています。中に私は今のところ必要2つのテーブルを1つではなく2つのテーブルで実行する
設定
映画
トレーラー
レビュー
final String SQL_CREATE_MOVIE__SETTING_TABLE = "CREATE TABLE " + MovieContract.MovieSettings.TABLE_NAME + " (" +
MovieContract.MovieEntry._ID + " INTEGER PRIMARY KEY, " +
MovieContract.MovieSettings.COL_MOVIE_SETTING + " TEXT UNIQUE NOT NULL " +
");";
final String SQL_CREATE_MOVIE_TABLE = "CREATE TABLE " + MovieContract.MovieEntry.TABLE_NAME + " (" +
MovieContract.MovieEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
MovieContract.MovieEntry.COL_MOVIE_KEY + " INTEGER NOT NULL, " +
MovieContract.MovieEntry.COL_MOVIE_ID + " INTEGER NOT NULL, " +
MovieContract.MovieEntry.COL_BACKDROP_PATH + " TEXT NOT NULL, " +
MovieContract.MovieEntry.COL_ORIGINAL_LANGUAGE + " TEXT NOT NULL, " +
MovieContract.MovieEntry.COL_ORIGINAL_TITLE + " TEXT NOT NULL," +
MovieContract.MovieEntry.COL_OVERVIEW + " TEXT NOT NULL, " +
MovieContract.MovieEntry.COL_TITLE + " TEXT NOT NULL, " +
MovieContract.MovieEntry.COL_VOTE_AVERAGE + " REAL NOT NULL, " +
MovieContract.MovieEntry.COL_VOTE_COUNT + " INTEGER NOT NULL, " +
MovieContract.MovieEntry.COL_POSTER_PATH + " TEXT NOT NULL, " +
MovieContract.MovieEntry.COL_DATE + " TEXT NOT NULL, " +
// Set up the location column as a foreign key to location table.
" FOREIGN KEY (" + MovieContract.MovieEntry.COL_MOVIE_KEY + ") REFERENCES " +
MovieContract.MovieSettings.TABLE_NAME + " (" + MovieContract.MovieSettings._ID + "), " +
// To assure the application have just one weather entry per day
// per location, it's created a UNIQUE constraint with REPLACE strategy
" UNIQUE (" + MovieContract.MovieEntry.COL_DATE + ", " +
MovieContract.MovieEntry.COL_MOVIE_KEY + ") ON CONFLICT REPLACE);";
final String SQL_CREATE_TRAILER_TABLE = "CREATE TABLE " + MovieContract.TrailerEntry.TABLE_NAME + " (" +
MovieContract.TrailerEntry._ID + " INTEGER PRIMARY KEY," +
MovieContract.TrailerEntry.COL_MOVIE_ID + " INTEGER NOT NULL, " +
MovieContract.TrailerEntry.COL_TRAILER_ID + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_ISO_369_1 + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_KEY + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_NAME + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_SITE + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_SIZE + " TEXT NOT NULL, " +
MovieContract.TrailerEntry.COL_TYPE + " TEXT NOT NULL, " +
// Set up the movie_id column as a foreign key to movie table.
" FOREIGN KEY (" + MovieContract.TrailerEntry.COL_MOVIE_ID + ") REFERENCES " +
MovieContract.MovieEntry.TABLE_NAME + " (" + MovieContract.MovieEntry.COL_MOVIE_ID + ") " +
" UNIQUE (" + MovieContract.TrailerEntry.COL_MOVIE_ID + ", " +
MovieContract.TrailerEntry.COL_TRAILER_ID + ") ON CONFLICT REPLACE);";
final String SQL_CREATE_REVIEW_TABLE = "CREATE TABLE " + MovieContract.ReviewEntry.TABLE_NAME + " (" +
MovieContract.ReviewEntry._ID + " INTEGER PRIMARY KEY," +
MovieContract.ReviewEntry.COL_MOVIE_ID + " INTEGER NOT NULL, " +
MovieContract.ReviewEntry.COL_REVIEW_ID + " TEXT NOT NULL, " +
MovieContract.ReviewEntry.COL_AUTHOR + " TEXT NOT NULL, " +
MovieContract.ReviewEntry.COL_CONTENT + " TEXT NOT NULL, " +
MovieContract.ReviewEntry.COL_URL + " TEXT NOT NULL, " +
// Set up the movie_id column as a foreign key to movie table.
" FOREIGN KEY (" + MovieContract.ReviewEntry.COL_MOVIE_ID + ") REFERENCES " +
MovieContract.MovieEntry.TABLE_NAME + " (" + MovieContract.MovieEntry.COL_MOVIE_ID + ") " +
" UNIQUE (" + MovieContract.ReviewEntry.COL_MOVIE_ID + ", " +
MovieContract.ReviewEntry.COL_REVIEW_ID + ") ON CONFLICT REPLACE);";
トレーラーテーブルをムービーテーブルに結合します。したがって、新しいトレーラーテーブルには次の列が必要です。
----------------------------------------------------------------------------------
|_id |movie_id |poster_path |id |iso_639_1 |key |name |site |size |type |
どちらは列が映画のテーブルに属しとposter_pathをmovie_id。私はposter_path列が欠落している。この表
--------------------------------------------------------------------
|_id |movie_id |id |iso_639_1 |key |name |site |size |type |
を得る。しかし
sTrailerByMovieIdQueryBuilder.setTables(
MovieContract.TrailerEntry.TABLE_NAME + " INNER JOIN " +
MovieContract.MovieEntry.TABLE_NAME + " ON " +
MovieContract.TrailerEntry.TABLE_NAME + "." +
MovieContract.TrailerEntry.COL_MOVIE_ID + " = " +
MovieContract.MovieEntry.TABLE_NAME + "." +
MovieContract.MovieEntry.COL_MOVIE_ID + " AND " +
MovieContract.MovieEntry.TABLE_NAME + "." +
MovieContract.MovieEntry.COL_POSTER_PATH
);
として内部結合を行います。私は私の内側の結合で何か間違っていましたが、私はそれを修正する方法がわかりません。ありがとう、
Theo。
、あなたが唯一の1つのテーブルの列を述べた:
あなたのクエリは次のようになります。 https://stackoverflow.com/questions/2366780/how-to-do-an-inner-join-on-multiple-columns –