私は 2 つの mysql テーブル、テーブルevent、およびテーブルを持っていますeventvenue。
会場から他のイベントを取得したい。
-------------- 表event: ---------------
id_e
id_event
title
content
-------------- 表eventvenue:--------------
id_ev
id_event_ev
id_location_ev
join を使用して、会場から他のイベントを取得します。
SELECT *
FROM eventvenue
JOIN event ON eventvenue.id_event_ev = event.id_event
WHERE eventvenue.id_location_ev=1
結果は次のとおりです。
id_ev id_event_ev id_location_ev id_e id_event タイトル コンテンツ ----- ----------- -------------- ---- -------- ------ -- ---------- 1 2 1 2 2 イベントA aaaaaaaaaaaaa 2 2 1 2 2 イベントA ああああああああ 1 4 1 4 4 イベント B bbbbbbbbb 1 9 1 9 9 イベント C cccccccc 3 5 1 5 5 イベント 5 555555
出力には、id_event_ev/の同じid_event値を持つ 2 つの行が含まれます2。
場所ごとに異なるイベント IDのみを表示するにはどうすればよいですか? このような:
id_ev id_event_ev id_location_ev id_e id_event タイトル コンテンツ ----- ----------- -------------- ---- -------- ------ -- ---------- 1 2 1 2 2 イベントA aaaaaaaaaaaaa 1 4 1 4 4 イベント B bbbbbbbbb 1 9 1 9 9 イベント C cccccccc 3 5 1 5 5 イベント 5 555555
注:id_evは重要ではありません。