rubing Posted February 9, 2008 Share Posted February 9, 2008 I have 2 tables MusicEvents & Bands: MusicEvents lists the bands that are playing on a given date at a given venue. Bands lists the websites and other info about the band. So, I am trying to generate a list of Bands from MusicEvents, that I do not have info yet. I do this by a Left Join between Music.EventsBand and Bands.Band. And then asking only for the band name when the BandSite column (band's website) is Null. As follows: SELECT DISTINCT MusicEvents.Band,BandSite FROM MusicEvents LEFT JOIN Bands ON MusicEvents.Band=Bands.Band WHERE BandSite IS NULL ORDER BY MusicEvents.Band ASC; This is kind of working. It seems that if a band is listed twice in my MusicEvents table, then even if it has a website address in the bands table, it is returned. I have tried Selecting just MusicEvents.Band as well as using a GROUP BY Band clause which did nothing. Can anybody please give me a clue as to how to eliminate this redundancy. Thank you!!! -GR Quote Link to comment https://forums.phpfreaks.com/topic/90227-distinct-with-left-join-returns-duplicates/ Share on other sites More sharing options...
rubing Posted February 9, 2008 Author Share Posted February 9, 2008 Ok, I urlencoded all of my resutls and found out there was an untrimmed space in front of some of the entries, which accounts for Distinct not sorting theses out. This is surprising! When I look through phpmyadmin for these entries. They do not show up as containing any leading whitespace. And of course they shouldn't b/c before I insert them into my database, I use php's trim command. maybe i should trim more spaces before insert? Quote Link to comment https://forums.phpfreaks.com/topic/90227-distinct-with-left-join-returns-duplicates/#findComment-462717 Share on other sites More sharing options...
fenway Posted February 9, 2008 Share Posted February 9, 2008 MySQL has a TRIM() command, too. Quote Link to comment https://forums.phpfreaks.com/topic/90227-distinct-with-left-join-returns-duplicates/#findComment-462808 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.