Solved

MS SQL n00b question on nested SELECT statement

Posted on 2009-04-14
3
350 Views
Last Modified: 2012-05-06
In the code section below you will find an SQL statement that works, but I want apply one extra "filter" to its result, perhaps by another SELECT statement?

When executing this query, I will get my results, but I want to filter those results out further by only getting records which match a particular test_name.

For example, test_name='aaa' .... how should I modify the query below? Thanks...
SELECT unique_id, test_name, test_object FROM tblSerializedTests
  WHERE unique_id IN 
   (SELECT unique_id FROM tblUserControls
    WHERE multiplicity='single'
      AND instrument='HP3245A'
      AND test_type='ACISource')

Open in new window

0
Comment
Question by:yaronusa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24142020
this could do:
SELECT unique_id, test_name, test_object FROM tblSerializedTests
  WHERE unique_id IN 
   (SELECT unique_id FROM tblUserControls
    WHERE multiplicity='single'
      AND instrument='HP3245A'
      AND test_type='ACISource')
  AND test_name = 'aaa'

Open in new window

0
 

Author Comment

by:yaronusa
ID: 24142115
For a n00b, I was pretty close, but I put the 'And test_name = aaa' in the WRONG place.

Thanks for helping me... it is very appreciated.

SELECT unique_id, test_name, test_object FROM tblSerializedTests
  WHERE unique_id IN /*AND test_name = 'aaa' <--I'm wrong */
   (SELECT unique_id FROM tblUserControls
    WHERE multiplicity='single'
      AND instrument='HP3245A'
      AND test_type='ACISource')
  AND test_name = 'aaa' /* <--you're right */

Open in new window

0
 

Author Closing Comment

by:yaronusa
ID: 31570127
For a n00b, I was pretty close, but I put the 'And test_name = aaa' in the WRONG place.

Thanks for helping me... it is very appreciated.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question