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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:30:08+00:00 2026-05-20T07:30:08+00:00

I have two SQL queries that I’m running from a C# winform, and I

  • 0

I have two SQL queries that I’m running from a C# winform, and I want to merge them.

The first is:

SELECT * FROM ES_TOOL INNER JOIN ES_HARDWARE ON ES_HARDWARE.eshw_ID = ES_TOOL.ESTOOL_HARDWARE 
                INNER JOIN ES_PAYMENT on ES_payment.espay_id = es_TOOL.estool_payment

This gives a list of all the tools and their associated payment and hardware requirements.

And the second is run on each record that the first query returns, by means of a c# for loop:

SELECT avg(a.esmrk_value) from ES_MARK a Inner Join ES_TOOL_CHAPTER b 
on  a.esmark_tool_chapter= b.estch_id WHERE b.estch_tool=@tool

This returns, for each tool, the average grade they’ve been awarded in the es_mark table.

N.B. Marks are awarded for individual “chapters” of tools. So, to find all the marks for a tool we need to see the ES_TOOL_CHAPTER table for a list of tool-chapters. Tool-chapters are what receive marks in the ES_MARK table.

I’ve tried grouping and more joins, but I’m just getting more confused by the minute, so I’d appreciate any help on the matter.
I’m basically looking for one query that will return all the results of the first query with an additional column for average mark.

Thanks.

Edit: the @tool represents the tool id.

  • 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-20T07:30:08+00:00Added an answer on May 20, 2026 at 7:30 am

    If you want to retrieve the average grade’s together with the main query:

    SELECT *
    FROM ES_TOOL
      INNER JOIN ES_HARDWARE ON ES_HARDWARE.eshw_ID = ES_TOOL.ESTOOL_HARDWARE 
      INNER JOIN ES_PAYMENT on ES_payment.espay_id = es_TOOL.estool_payment
      LEFT JOIN (
        SELECT b.estch_tool, avg(a.esmrk_value) AvgValue
        FROM ES_MARK a
          Inner Join ES_TOOL_CHAPTER b 
            ON a.esmark_tool_chapter = b.estch_id
        GROUP BY b.estch_tool
      ) g ON ES_TOOL.ToolColumn =  g.estch_tool
    

    Replace ToolColumn with the correct column name.

    Note: SELECT * is not recommended, please read This question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two SQL queries, where the first one is: select Activity, SUM(Amount) as
I have two sql queries select * from table1 ORDER BY column1 Select top
i have two sql queries. select EmployeeID,FName from [Mydatabase].[dbo].EMPLOYEE_TABLE where EmployeeID not in (select
I have two SQL queries producing different results when I would expect them to
I am writing my first little Access 2003 application. I have two queries that
I have the following two SQL statements First one: IF(@User_Id IS NULL) BEGIN SELECT
I have two SQL scripts which get called within a loop that accept a
I am using SQL Server 2000 and I have two databases that both replicate
I've got two PostgreSQL databases that have been created using the same sql file.
I have two different DataContexts (SQL Databases) that have the same data, just with

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.