Results 1 to 2 of 2

Thread: Select Not In Other Tables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Select Not In Other Tables

    I am trying to come up with a way to determine which of my customers are not coming back in a 3 month time period. For instance I want to know which customers came to my store in January but did not come back in February, March or April.

    My query looks like this:

    Code:
    SELECT 
    	CustomerID, LastName, FirstName
    FROM 
    	vJan 
    WHERE
    	CustomerID NOT IN (Select CustomerId From vFeb) And
    	CustomerID NOT IN (Select CustomerId From vMar) And
    	CustomerID NOT IN (Select CustomerId From vApr)
    	ORDER BY LastName, FirstName
    I thought that this is the correct way to write it but I am getting o rows returned and I know for a fact that not every customer who came in January has been back. What am I doing wrong?

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Select Not In Other Tables

    Try this:

    Code:
    SELECT 
    	CustomerID, LastName, FirstName
    FROM 
    	vJan 
    WHERE
    	vJan.CustomerID NOT IN (Select vFeb.CustomerId From vFeb) And
    	vJan.CustomerID NOT IN (Select vMar.CustomerId From vMar) And
    	vJan.CustomerID NOT IN (Select vApr.CustomerId From vApr)
    	ORDER BY LastName, FirstName

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width