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

  • SEARCH
  • Home
  • 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 7520347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:03:22+00:00 2026-05-30T02:03:22+00:00

I got some problems with this query i need all my selectors but i

  • 0

I got some problems with this query i need all my selectors but i only want to group aspnet_Users.Userid how should i do this?

Here is my query:

SELECT 
    aspnet_Users.UserId, aspnet_Users.UserName, 
    Friends.Verified, Friends.FriendUserId 
FROM 
    [aspnet_Users] 
INNER JOIN 
    Friends ON Friends.UserId = aspnet_Users.UserId OR Friends.FriendUserId = aspnet_Users.UserId
WHERE
    aspnet_Users.UserId IN 
       (SELECT UserId as Id FROM Friends 
        WHERE FriendUserId='3d1224ac-f2ad-45d4-aa84-a98e748e3e57'
        UNION 
        SELECT FriendUserId as Id FROM Friends 
        WHERE UserId='3d1224ac-f2ad-45d4-aa84-a98e748e3e57')
GROUP BY 
    aspnet_Users.UserId, aspnet_Users.UserName, 
    Friends.Verified, Friends.FriendUserId

Stored Procedure structure:

Tables [aspnet_Users] and [Friends]

Columns [aspnet_Users.UserId], [aspnet_Users.UserName], [Friends.Verified], [Friends.FriendUserId]

That is the data that i need to get using the procedure, but the problem is that each user can have multiply friends which means if so there will be multiply Friends values. This is the reason why i can’t group using those values cause it gives me dublicates with the wrong value.

Expected Output:

aspnet_Users.UserId (This is the user id of the friend, note that it doesn’t mean that its the FriendUserId)

aspnet_Users.UserName (This is the UserName of the friend based on the UserId explained above)

Friends.Verified (True or False. The Verified value in the Friends table on the friendship)

Friends.FriendUserId (The FriendUserId value from the table Friends)

  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-05-30T02:03:22+00:00Added an answer on May 30, 2026 at 2:03 am

    If your relationship is not fully reciprocal in the table Friends, you can use this query.

    Otherwise either part of the UNION would work on its own

    SELECT U.UserId, U.UserName, F.Verified, F.FriendUserId
    FROM Friends F
    JOIN aspnet_Users U ON U.UserId=F.UserId
    WHERE F.FriendUserId='3d1224ac-f2ad-45d4-aa84-a98e748e3e57'
    UNION 
    SELECT U.UserId, U.UserName, F.Verified, F.FriendUserId
    FROM Friends F
    JOIN aspnet_Users U ON U.UserId=F.FriendUserId
    WHERE F.UserId='3d1224ac-f2ad-45d4-aa84-a98e748e3e57'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this a problem, I need translate this SQL Query to Criteria, but
All, I'm trying to resolve some performance problems and I've got as far as
I got some problems with finding a bug in php/mysql application, and I wonder
I got some problems with EOF and stdio in a communication pipeline between a
We've got some problems with an external company trying in integrate into a WCF
I've got some problems on a .NET site where both Latin (åäö) and Latvian
I am just starting with C++ and got some problems in understanding how the
i'm new to java and i got some problems. i'm developping a web application
I'm working on a online game. I got some problems with inserting new data
I've got some tabs. http://img196.imageshack.us/img196/7167/tabs.gif And I want to add a rollover effect. Problem

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.