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] Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/ 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. Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/#findComment-155837 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] Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/#findComment-155841 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. Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/#findComment-155853 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"? Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/#findComment-156073 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! Link to comment https://forums.phpfreaks.com/topic/33352-solved-two-queries-at-once/#findComment-156082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.