Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...SQL query displays users twiceSQL query displays users twice
Previous
 
Next
New Post
5/26/2010 12:02 AM
 
I'm using the query below to return a list of users. Unfortunately it is showing each user between 2 and 4 times, even though they only appear in the user list once, and only exist once. Clearly I'm doing something wrong, can someone please advise? (Note: The query works perfectly aside from this issue).

SELECT
  u.LastName AS [Last Name],  u.FirstName AS [First], upd.Profession, upd.Region, u.Email
FROM dbo.Users as u INNER JOIN
  dbo.UserRoles AS ur ON u.UserID = ur.UserID  INNER JOIN
  (SELECT      
    up.UserID,  
    MAX(CASE WHEN ppd.PropertyName = 'Profession' THEN up.PropertyValue ELSE '' END) AS Profession,
    MAX(CASE WHEN ppd.PropertyName = 'Region' THEN up.PropertyValue ELSE '' END) AS Region
   FROM           
    dbo.UserProfile AS up INNER JOIN 
    dbo.ProfilePropertyDefinition AS ppd ON up.PropertyDefinitionID = ppd.PropertyDefinitionID AND ppd.PortalID = 0 
   GROUP BY up.UserID) AS upd ON u.UserID = upd.UserID
 
New Post
5/26/2010 4:50 AM
 
this is caused by your joins, you get one record per property. You might use a left join with an appropriate subquery instead.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
5/26/2010 6:46 PM
 
Legend. Thank you Sebastian.
 
New Post
5/26/2010 7:15 PM
 
here is a sample from another site:

SELECT U.UserID, U.DisplayName, U.FirstName, U.LastName, U.Username, U.Email, P0.Company, P1.Country
FROM dbo.Users AS U
 LEFT OUTER JOIN (SELECT UP.UserID, UP.PropertyValue AS Company FROM dbo.UserProfile AS UP
                                     INNER JOIN dbo.ProfilePropertyDefinition AS PD ON UP.PropertyDefinitionID = PD.PropertyDefinitionID
                                     WHERE (PD.PropertyName LIKE 'Company')) AS P0 ON U.UserID = P0.UserID
 LEFT OUTER JOIN (SELECT UP.UserID, UP.PropertyValue AS Country FROM dbo.UserProfile AS UP
                                     INNER JOIN dbo.ProfilePropertyDefinition AS PD ON UP.PropertyDefinitionID = PD.PropertyDefinitionID
                                     WHERE (PD.PropertyName LIKE 'Country')) AS P1 ON U.UserID = P1.UserID 
WHERE U.UserID IN
(SELECT User FROM dbo.UserRoles WHERE (RoleID = 5)) /*select members of a specific role */


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
5/31/2010 7:39 PM
 
Thanks for your help Seb, I got your format to work but it still returned several instances of each user, I then used 'SELECT DISTINCT' with your format and it worked perfectly.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...SQL query displays users twiceSQL query displays users twice


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out