Reputation: 209
I want to show records from table name station where station have at least one song in song table. Table structure
station
station_id
stration_name
station_description
song
song_id
station_id
song_location
Please suggest me the way to form query that shows me station data which have songs in song table.please specify a way that do not returns record with corresponding songs zero count.
Upvotes: 0
Views: 39
Reputation: 2254
What you're looking for is a INNER JOIN. You could join your stations table with your songs table by stations.station_id
and songs.station_id
. This will work because INNER JOIN only return rows for which the join-predicate is satisfied.
I've made an example available at SQL Fiddle, but I do recommend spending a few minutes understanding mechanics of JOIN.
Upvotes: 1
Reputation: 2220
You could join the tables together at station_id
.
It looks like each song is linked to a spesific station. Meaning where these ID (station_id
) is equal, the station has this song...
Upvotes: 0
Reputation: 33945
SELECT DISTINCT something
FROM somewhere
JOIN somewhere_else
ON somewhere_else.other_thing = somewhere.thing;
Upvotes: 0