Solved

MS SQL n00b question on nested SELECT statement

Posted on 2009-04-14
3
344 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
  • 2
3 Comments
 
LVL 142

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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now