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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:27:38+00:00 2026-05-13T08:27:38+00:00

I am trying to inner join 2 temp tables I know this can be

  • 0

I am trying to inner join 2 temp tables
I know this can be done, I have done this before but i completely forgot how to do it

Please advise me
Below is the query that I try to execute

select tmp1.*, tmp2.cnt from
(
    select 
        1 as ClassificationType,
        tblMatches.IdGame,
        tblMatches.IdPlayer,
        sum(Score) as Score, sum(Points) as Points, sum(OpponentScore) as OpponentScore,
        count(ID) as MatchesCount, count(distinct IdCompetition) as CompetitionsCount
    from 
        tblMatches  
    group by IdPlayer, IdGame   
) as tmp1
inner join (select IdWinner, count(IdWinner) as cnt from tblCompetitions where IdWinner = tmp1.IdPlayer) as tmp2 
            on tmp2.IdWinner = tmp1.IdPlayer

This will fail with
I think I am not allowed to use tmp1 in the subquery that create tmp2

Msg 4104, Level 16, State 1, Line 17
The multi-part identifier
“tmp1.IdPlayer” could not be bound.

  • 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-13T08:27:39+00:00Added an answer on May 13, 2026 at 8:27 am

    You are not trying to join two temp tables, but two derived tables.

    You cannot access the inner data of one derived table in outside of it unless it’s in the SELECT clause.

    Try the following:

    select tmp1.*, tmp2.cnt from
    (
        select 
            1 as ClassificationType,
            tblMatches.IdGame,
            tblMatches.IdPlayer,
            sum(Score) as Score, sum(Points) as Points, sum(OpponentScore) as OpponentScore,
            count(ID) as MatchesCount, count(distinct IdCompetition) as CompetitionsCount
        from 
            tblMatches      
        group by IdPlayer, IdGame   
    ) as tmp1
    inner join (select IdWinner, count(IdWinner) as cnt from tblCompetitions GROUP BY IdWinner) as tmp2 
                    on tmp2.IdWinner = tmp1.IdPlayer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning mysql and have been trying to get this working, but an error
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I've trying to do an inner join select statement where I select two fields
I'm trying to count how many essays have been graded so I know how
Trying to get my css / C# functions to look like this: body {
Trying to make a make generic select control that I can dynamically add elements
Trying to keep all the presentation stuff in the xhtml on this project and
Not sure if this question makes for some poor performance down the track, but
I have a SQL variable @SumScore dec(9,4) I am trying to assign the variable
How can this be achieved in SQL (MS SQL) Thanks OK: let me bit

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.