2013-03-22 17 views
0

我想顯示歌曲表中至少有一首歌曲的表名站的記錄。 表結構從MySQL中的表中獲取數據,必須在另一個表中有相應的記錄

station 
station_id 
stration_name 
station_description 

song 
song_id 
station_id 
song_location 

請給我建議,形成查詢,顯示我已經在歌曲table.please歌指定的方式,不具有相應的歌曲零計數返回記錄臺站數據的方式。

+0

你試過什麼嗎? – 2013-03-22 09:50:06

回答

1

你在找什麼是INNER JOIN。您可以通過stations.station_idsongs.station_id加入您的歌曲表格。這將工作,因爲INNER JOIN只返回滿足連接謂詞的行。

我在SQL Fiddle上提供了一個示例,但我建議花費幾分鐘的時間來理解JOIN的機制。

0
SELECT DISTINCT something 
      FROM somewhere 
      JOIN somewhere_else 
      ON somewhere_else.other_thing = somewhere.thing; 
0

你可以在station_id加入表格。
它看起來像每首歌都鏈接到一個特定的電臺。這些ID的意思是(station_id)相等,電臺有這首歌...

相關問題