954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mysql Join Query using distinct

Hi

I am using the following join query to get a list of stores that have sold policies during the day.

But I need it to be distinct

$Query = mysql_query("SELECT  tblpolicies.StoreId
                     , tblpolicies.DateReceived
                     , DailyGroup.GroupName
                     , DailyGroup.StoreName
                     , DailyGroup.PortfolioName
                     FROM tblpolicies
                     LEFT OUTER
                     JOIN (SELECT StoreId
                                , GroupName, StoreName, PortfolioName
                           FROM tblstores GROUP BY StoreId) AS DailyGroup
                           ON tblpolicies.storeId = DailyGroup.StoreId
                     WHERE DateReceived ='2010-07-01' ORDER BY GroupName


When I try using DISTINCT it doesnt work properly

$Query = mysql_query("SELECT DISTINCT tblpolicies.StoreId
                     , tblpolicies.DateReceived
                     , DailyGroup.GroupName
                     , DailyGroup.StoreName
                     , DailyGroup.PortfolioName
                     FROM tblpolicies
                     LEFT OUTER
                     JOIN (SELECT StoreId
                                , GroupName, StoreName, PortfolioName
                           FROM tblstores GROUP BY StoreId) AS DailyGroup
                           ON tblpolicies.storeId = DailyGroup.StoreId
                     WHERE DateReceived ='2010-07-01' ORDER BY GroupName")
fabzster
Light Poster
40 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

What does "not properly" mean?

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

Select data from table group by storeid

jlego
Posting Pro
529 posts since Mar 2009
Reputation Points: 31
Solved Threads: 41
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: