Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Unanswered: sub query select help

    I have the following three tables where the table "RepByZip" contains the foreign keys values for a many-to-many relationship.

    CREATE Table dbo.RepList
    RepId int IDENTITY (1,1) PRIMARY KEY,
    FirstName varchar(50) NOT NULL,
    LastName varchar(50) NOT NULL,
    Email varchar(50) NOT NULL

    CREATE Table dbo.PostalCodes
    ZipId int IDENTITY (1,1) PRIMARY KEY,
    PostalCode varchar(5) NOT NULL,

    CREATE Table dbo.RepByZip
    RepId int
    ZipId int

    I'm trying to create a select statement that obtains the emails from the "RepList" table where I pass in the zipcode as a parameter...i.e. @zipcode. I think I need use a sub query or an inner join, but can't figure it out.

    Create Procedure GetRepEmail
    @zipcode varchar(5),
    SELECT email
    FROM RepList
    WHERE @zipcode =

    Thanks for any help.

  2. #2
    Join Date
    Jan 2004
    In a large office with bad lighting
    You are on the right track. You will need a three table join to retrieve the information you need. All the joins will be inner joins.

    -- This is all just a Figment of my Imagination --

Posting Permissions

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