john_grimsby Posted September 11, 2006 Share Posted September 11, 2006 HelloI am trying to build a reggae 7" single discography database, with three tablesRECORD LABEL ([u]record_label_ref[/u], record_label, country, subsidiary_of, label_info)ARTIST ([u]artist_ref[/u], artist_name, artist_info)RECORD ([u]record_ref[/u], cat_no, [i]record_label_ref[/i], label_display, [i]artist_ref_a[/i], song_a, [i]artist_ref_b[/i], song_b, year)As you can see, each record has two artists, one on each side. I want a query which displays the information for each record like so (I've omitted a few columns for simplicty):PAMA 1 (A) ARTIST A Song A c/w (2) ARTIST B Song B (1960)So far I have got the query:SELECT record_label.record_label, record.cat_no, label_display, artist_ref_a, artist.artist_name, song_a, composer_a, producer_a, arranger_a, artist_ref_b, artist.artist_name, song_b, composer_b, producer_b, arranger_b, year, est_value, rarity_rating, rec_infoFROM record, record_label, artistWHERE record.record_label_ref = $record_label_refAND record.artist_ref_a = artist.artist_refAND record.artist_ref_b = artist.artist_refAND record.record_label_ref = record_label.record_label_ref;However, this query will only display records where artist_ref_a is the same as artist_ref_b.CAN ANYONE PLEASE HELP - IT'S DRIVNG ME CRAZY!!!! Quote Link to comment Share on other sites More sharing options...
fenway Posted September 11, 2006 Share Posted September 11, 2006 You'll need to JOIN in the the artist table twice to do this properly. Quote Link to comment Share on other sites More sharing options...
john_grimsby Posted September 11, 2006 Author Share Posted September 11, 2006 Cheers mate, can you give me a quick pointer my heads spinning and i can't think straight - it took me about 10 hours to get that first query!! Quote Link to comment Share on other sites More sharing options...
fenway Posted September 11, 2006 Share Posted September 11, 2006 This should be close, but it's untested:[code]SELECT record_label.record_label, record.cat_no, label_display, artist_ref_a, artistA.artist_name, song_a, composer_a, producer_a, arranger_a, artist_ref_b, artistB.artist_name, song_b, composer_b, producer_b, arranger_b, year, est_value, rarity_rating, rec_infoFROM record INNER JOIN record_label ON ( record.record_label_ref = record_label.record_label_ref )INNER JOIN artist AS artistA ON ( record.artist_ref_a = artistA.artist_ref )INNER JOIN artist AS artistB ON ( record.artist_ref_b = artistB.artist_ref )WHERE record.record_label_ref = $record_label_ref[/code] Quote Link to comment Share on other sites More sharing options...
john_grimsby Posted September 11, 2006 Author Share Posted September 11, 2006 Thanks - IT WORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Peace man, I hope you have a good day, nice to know there's people who help others for no financial gain! :D Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 12, 2006 Share Posted September 12, 2006 Aye up cod head!!!!(that is if you from GY UK not GY Canada!)You may guess from my screen name that I am an exile in geordie land!Welcome to phpfreaks anyway matey.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.