SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: joining tables

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Rocky Mount, NC
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    joining tables

    Okay. I need to join tables to make this work. Lets see. I have a database the following tables:

    TABLE "SONGS"
    |songID
    |songName
    |songArtist
    |songRequest

    TABLE "STATIONS"
    |stationID
    |stationName
    |stationCity
    |stationState
    |stationSite

    then I have the channel table to join them:

    TABLE "CHANNEL"
    |songID
    |stationID

    On my site I will need to list all the stations listed with any given song. Say I need the song Butterfly that was heard on the stations KISS FM, K98, and Star94, how would I get those pulled from the database?
    Stuart Briscar Consulting - Free Website Consulting

  2. #2
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT stationName,stationCity,stationState,stationSite 
    FROM STATIONS, SONGS, CHANNEL 
    WHERE CHANNEL.songID = SONGS.songID AND
          CHANNEL.stationID = STATIONS.stationID AND
          SONGS.songName = 'Butterfly'

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey what I always wanted to know, does it make any difference between what "oodie" says and this here using a LEFT JOIN:
    PHP Code:
    SELECT stationName,stationCity,stationState,stationSite 
    FROM STATIONS LEFT JOIN SONGS ON STATIONS
    .stationID SONGS.songID WHERE SONGS.songName 'Butterfly'


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •