How do I filter one of the columns in a SQL Server SQL Query

Posted by Kent S. Clarkson on Stack Overflow See other posts from Stack Overflow or by Kent S. Clarkson
Published on 2010-05-21T11:18:08Z Indexed on 2010/05/21 11:20 UTC
Read the original article Hit count: 310

Filed under:
|
|

I have a table (that relates to a number of other tables) where I would like to filter ONE of the columns (RequesterID) - that column will be a combobox where only people that are not sales people should be selectable.

Here is the "unfiltered" query, lets call it QUERY 1:

SELECT RequestsID, RequesterID, ProductsID
FROM dbo.Requests

If using a separate query, lets call it QUERY 2, to filter RequesterID (which is a People related column, connected to People.PeopleID), it would look like this:

SELECT     People.PeopleID
FROM         People INNER JOIN
                  Roles ON People.RolesID = Roles.RolesID INNER JOIN
                  Requests ON People.PeopleID = Requests.RequesterID
WHERE     (Roles.Role <> N'SalesGuy')
ORDER BY Requests.RequestsID

Now, is there a way of "merging" the QUERY 2 into QUERY 1?

(dbo.Requests in QUERY 1 has RequesterID populated as a Foreign Key from dbo.People, so no problem there... The connections are all right, just not know how to write the SQL query!)

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-query