Jump to content

Distinct with Left Join returns duplicates


rubing

Recommended Posts

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

 

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?

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.