Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 144497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:15:45+00:00 2026-05-11T08:15:45+00:00

should be simple enough but it’s causing me a couple of issues. I have

  • 0

should be simple enough but it’s causing me a couple of issues.

I have a data set similar to the following:

User   UserID   Name   Age  UserPropertyValues   UserID   PropertyCodeValueID  PropertyCodes   PropertyCodeID   PropertyCodeName  PropertyCodeValues   PropertyCodeValueID   PropertyCodeID   PropertValue 

Now let’s assume the tables contain the following data:

1  John  25 2  Sarah  34  1  2 1  3 2  1 2  3  1  FavColour 2  CarMake 3  PhoneType  1  1  Blue 2  1  Yellow 3  2  Ford 4  3  Mobile 5  3  Landline 

Now from this I’m looking to create a view to return the User details, as well as the property values for Property code 1 and 2 like so:

John 25 Yellow Ford Sarah 34 Blue Ford 

The queries I have tried so far tend to return repeating rows of data :

John 25 Yellow John 25 Ford Sarah 34 Blue Sarah 34 Ford 

Any help is appreciated, thank you all in advance.

  • 1 1 Answer
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:15:46+00:00Added an answer on May 11, 2026 at 8:15 am

    Input data:

    DECLARE @User TABLE (UserID INT, Name VARCHAR(10), Age INT) INSERT INTO @User SELECT 1,  'John',  25 UNION SELECT 2,  'Sarah',  34 DECLARE @UserPropertyValues TABLE(UserID INT, PropertyCodeValueID INT) INSERT INTO @UserPropertyValues SELECT 1, 2 UNION SELECT 1, 3 UNION SELECT 2, 1 UNION SELECT 2,  3 DECLARE @PropertyCodes    TABLE (PropertyCodeID INT, PropertyCodeName VARCHAR(10)) INSERT INTO @PropertyCodes SELECT 1,  'FavColour' UNION SELECT 2,  'CarMake' UNION SELECT 3,  'PhoneType' DECLARE @PropertyCodeValues TABLE (PropertyCodeValueID INT,    PropertyCodeID INT, PropertValue VARCHAR(10)) INSERT INTO @PropertyCodeValues SELECT 1,  1,  'Blue' UNION SELECT 2,  1,  'Yellow' UNION SELECT 3,  2,  'Ford' UNION SELECT 4,  3,  'Mobile' UNION SELECT 5,  3,  'Landline' 

    If two properties is all that you need in result, and each user have those properties, then try this:

    SELECT U.Name, U.Age, PCVFC.PropertValue, PCVCM.PropertValue  FROM @User U INNER JOIN @UserPropertyValues UPVFC ON U.UserID = UPVFC.UserID  INNER JOIN @PropertyCodeValues PCVFC    ON UPVFC.PropertyCodeValueID = PCVFC.PropertyCodeValueID      AND PCVFC.PropertyCodeID = 1 INNER JOIN @UserPropertyValues UPVCM ON U.UserID = UPVCM.UserID  INNER JOIN @PropertyCodeValues PCVCM    ON UPVCM.PropertyCodeValueID = PCVCM.PropertyCodeValueID      AND PCVCM.PropertyCodeID = 2 

    [edit] But to handle possible NULL values better use this:

    SELECT U.Name, U.Age, FC.PropertValue, CM.PropertValue  FROM @User U LEFT JOIN (   SELECT UserID, PropertValue FROM @UserPropertyValues  UPV     INNER JOIN @PropertyCodeValues PCV        ON UPV.PropertyCodeValueID = PCV.PropertyCodeValueID          AND PCV.PropertyCodeID = 1 ) FC ON U.UserID = FC.UserID LEFT JOIN (   SELECT UserID, PropertValue FROM @UserPropertyValues  UPV     INNER JOIN @PropertyCodeValues PCV        ON UPV.PropertyCodeValueID = PCV.PropertyCodeValueID          AND PCV.PropertyCodeID = 2 ) CM ON U.UserID = CM.UserID 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should simple JavaBeans that have only simple getters and setters be unit tested?? What
Should be simple and quick: I want a C# equivalent to the following Java
I know this should be simple and I should know it but it's eluding
Should be pretty simple: I have an InputStream where I want to peek at
This should be a simple question, but I haven't been able to find a
This should be a really really simple thing, but for some reason it is
My scenario should be simple... the type I want to convert FROM is ALWAYS
I'm attempting to do something which should be relatively simple. I'm using a ListView
This should hopefully be a simple one. I would like to add an extension
Should my ajax calls talk to webservices or to simple webpages? It seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.