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 9070539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:42:23+00:00 2026-06-16T17:42:23+00:00

It’s hard to get a good title for this question, but i will explain

  • 0

It’s hard to get a good title for this question, but i will explain it thoroughly below. I’ll be simplifying these tables a bit to make the question a bit easier to ask.

I have a table called ‘User’ with the following columns:

UserRowId (PK)
FirstName
LastName
RegionRowId (FK)
Active

I have a table called ‘Region’ with the following columns:

RegionRowId
RegionDesc
UserRowId

The logic here is, a user belongs to a ‘Region’ which is noted by the RegionRowId in the User table. Each region (in the ‘Region’ table) has a regional manager which is noted by the ‘UserRowId’ column in the ‘Region’ table (a FK from the ‘User’ table).

I have a table called ‘UserTime’ with the following columns:

UserTimeRowId (PK)
UserRowId (FK)
Hours
Sales

The logic here is a user (mapped by UserRowId) reports hours and sales which get stored in this table. Each time a user reports sales/hours, a new row is created.

What I’m trying to accomplish:

I’m trying to write a query that will pull the FirstName, LastName, the regional manager for this user, the sum of the hours, and the sum of the sales.

Here’s what i have so far:

Query:

SELECT dbo.[User].FirstName, dbo.[User].LastName,
dbo.[Region].UserRowId AS RegManager, dbo.[Region].RegionDesc AS Desc,
SUM(dbo.[UserTime].Sales) AS Sales, SUM(dbo.[UserTime].Hours) AS Hours
FROM dbo.[UserTime]
INNER JOIN dbo.[User] ON dbo.[UserTime].UserRowid = dbo.[User].UserRowId
INNER JOIN dbo.[Region] ON dbo.[User].RegionRowId = dbo.[Region].RegionRowId
WHERE dbo.[User].Active = 1
GROUP BY dbo.[User].FirstName, dbo.[User].LastName,
dbo.[Region].UserRowId, dbo.[Region].RegionDesc

Output (example):

FirstName   LastName   RegManager   RegionDesc   Sales   Hours
Bob         Man        773          NYC          500     5

What i am having trouble with is:

I cannot (for the life of me) get the LastName of the regional manager (RegManager column in the output above) instead of the UserRowId. I know in my query i am pulling dbo.[Region].UserRowId so obviously that’s what i’ll get in the output. However, what i need is to use that ID to cross-reference the User table to pull the name of that manager.

When i try to join the user table and the region table by the UserRowId, i get a list of regional managers instead of a list of users, and a column of the regional managers for that user.

Do i need a subquery in there to accomplish this?

Any help is appreciated and please let me know if I need to clarify anything to get to a solution.

Thank you

  • 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-06-16T17:42:24+00:00Added an answer on June 16, 2026 at 5:42 pm

    You don’t need subqueries, but you need to use aliases, so that you can JOIN the same table (the user table in this case) multiple times without creating an ambiguity.

    SELECT u.FirstName, u.LastName,
    m.FirstName AS RegManagerFirstName, m.LastName AS RegManagerLastName, r.RegionDesc AS [Desc],
    SUM(ut.Sales) AS Sales, SUM(ut.Hours) AS Hours
    FROM dbo.[UserTime] AS ut
    INNER JOIN dbo.[User] AS u ON ut.UserRowid = u.UserRowId
    INNER JOIN dbo.[Region] AS r ON u.RegionRowId = r.RegionRowId
    INNER JOIN dbo.[User] AS m ON r.UserRowid = m.UserRowId
    WHERE u.Active = 1
    GROUP BY u.FirstName, u.LastName, m.FirstName, m.LastName, r.RegionDesc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text

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.