Link to home
Start Free TrialLog in
Avatar of yaronusa
yaronusa

asked on

MS SQL n00b question on nested SELECT statement

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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yaronusa
yaronusa

ASKER

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

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.