Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS SQL n00b question on nested SELECT statement

Posted on 2009-04-14
3
Medium Priority
?
357 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

660 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