michaellunsford Posted January 8, 2007 Share Posted January 8, 2007 The main query is pretty simple. The catch is, I only want DISTINCT `clientimages`.`event_name` fields. So, I'm thinking I need to embed a DISTINCT query inside the following?[code]"SELECT `clientimages`.*,`options`.`value` WHERE `clientimages`.`event_name` = `options`,`keyfield`"[/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 Instead of[tt] `clientimages`.*[/tt], I think you need to specify the[tt] DISTINCT [/tt]for[tt] event_name[/tt], and then list the other fields. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 8, 2007 Author Share Posted January 8, 2007 not terribly good at this, here's what I have -- but it's returning every record:[code]SELECT DISTINCT `clientimages`.`event_name`, `clientimages`.`caption` , `options`.`value` FROM `clientimages` , `options` WHERE `clientimages`.`event_name` = `options`.`keyfield` [/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 I think I'm wrong here:[tt] DISTINCT [/tt]is affecting the whole sets of fields, not just [i]a[/i] field. See if the some of the User Comments [url=http://dev.mysql.com/doc/refman/5.0/en/select.html]here[/url] are helpful; I saw two that specifically dealt with this. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 8, 2007 Share Posted January 8, 2007 Correct -- DISTINCT is not a function, it's a modified to SELECT. I'd suggest a GROUP BY clause, but why do you duplicate records, and which one would you want MySQL to "keep"? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 8, 2007 Author Share Posted January 8, 2007 the records aren't duplicate, it's just a linked field. like a category. So I only want one from each category returned.anyway, the "group by" has done the trick. Thanks! 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.