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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:50:53+00:00 2026-05-22T12:50:53+00:00

I have 3 tables that look something like this: Table1 Users: ID Name Score

  • 0

I have 3 tables that look something like this:

Table1 Users:

  • ID
  • Name
  • Score

Table2 Game:

  • ID
  • Name
  • Fouls

Table 3 Game2

  • ID
  • Name
  • Fouls

What I would like to do is to in Table1, select all users.
Then select all data where Table1.Name = Table2.Name OR Table1.Name = Table3.Name but with higher priority to Table2, so if there is a match Table1.Name = Table2.Name no join from Table 3 will be made. Then when I’ve selected the correct that I also would like to count the totalt sum of Score and Fouls.

How is this done in SQL and is it possible? I am using MSSQL

  • 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-22T12:50:54+00:00Added an answer on May 22, 2026 at 12:50 pm
    SELECT
      SUM(t1.Score) AS TotalScore,
      SUM(COALESCE(t2.Fouls, t3.Fouls)) AS TotalFouls
    FROM Table1 t1
      LEFT JOIN Table2 t2 ON t2.Name = t1.Name
      LEFT JOIN Table3 t3 ON t3.Name = NULLIF(t1.Name, t2.Name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that look as Follows: Person (Table Name) Name1/Phone1/Email1/Address1/Organization1/Notes1 (Fields) Organization
In my database I have tables that define types for example Table: Publication Types
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have a few tables that I've defined like the below examples: class TableA
I am working with a legacy database schema that looks like this: product_table table
I have a table like this: Table A Customer InvoiceNo Region Type Amount A001
I have two tables that are joined together. A has many B Normally you
I have some tables that I build as a part of my report rollup.
I have some tables that represent various types. They usually just consist of an
Ok, I have two tables that I am joining and doing a select on

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.