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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:43:34+00:00 2026-06-17T19:43:34+00:00

Need some help with a SQL query. I have three tables TestOptions, CreateScript and

  • 0

Need some help with a SQL query.

I have three tables TestOptions, CreateScript and TestResults.

Testoptions holds all data for a particular test. CreateScript holds collections of tests which are run in order, denoted by index. TestResults hold the results.

I want to display a list of tests for a particular instrument. The list will contain. TestType, TestName, limits of the test and the result. Some tests may not have been carried out yet so the there will be no entry for that test in the test results table. If there the test has not been carried out, the test details still need to be retrieved. The list will be ordered by index and grouped by TestType.

So far I’ve got:

SELECT TestType, TestName, LowerLimits, UpperLimits, ResultRecorded  
FROM CreateScriptTable 
INNER JOIN TestOptionsTable ON CreateScriptTable.TestName =T estOptionsTable.TestName 
LEFT JOIN TestResultsTable ON CreateScriptTable.TestName = TestResultsTable.TestName 
WHERE CreateScriptTable.InstrumentType= 'instType' 
AND jobNo ='000'
AND SerialNo ='000'
ORDER BY [Index] ASC, TestType

SerialNo and JobNo are only in TestResults table.
This query only gives the details of the tests that have been entered in the test results table. I would like all test details and the result if the test has been completed.

The expected output is as follows:

TestType    TestName    Lower       Upper       Result
type1       test1       12            20        12
type1       test2       96           108        105
type2       test2       98           108        
type3       test3       95           105

The actual output is more like

TestType    TestName    Lower       Upper       Result
type1       test1       12            20        12
type1       test2       96            108       105

Only tests with entries in the results table showing.

Possibly I am not approaching the joins correctly. I have messed around with inner, left, right and full joins but to no avail and am pretty stumped right now.

  • 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-17T19:43:36+00:00Added an answer on June 17, 2026 at 7:43 pm

    You can move your criteria for columns in the left-joined table from the WHERE clause to the JOIN clause to prevent them from virtually changing your left join to an inner join like so:

    SELECT TestType, TestName, LowerLimits, UpperLimits, ResultRecorded  
    FROM CreateScriptTable 
    INNER JOIN TestOptionsTable ON CreateScriptTable.TestName =TestOptionsTable.TestName 
    LEFT JOIN TestResultsTable ON CreateScriptTable.TestName = TestResultsTable.TestName AND jobNo ='000' AND SerialNo ='000'
    WHERE CreateScriptTable.InstrumentType= 'instType' 
    ORDER BY [Index] ASC, TestType
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help to build SQL Query. I have table having data like:
I need some help with SQL Query. I am trying to select all records
i need some help with a sql query. I have a table called 'table1'
I am new to SQL Server 2008, and I need some help in query
I need some help in explaining this behavior in SQL Server 2008. I have
I need some help with a T-SQL query. I want to count fields that
need some your help with a query. I have a table Managers (ManagerId, ManagerName)
I need some help getting a SQL query running the way I need. I
I’m trying to develop a SQL query to help me extract some data from
I need some help in building the correct query. I have an Employees table.

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.