SELECT from a table WHERE fields are LIKE results from another table

  • I need to SELECT from a table where the fields are LIKE the results from another. I believe I can not use the IN clause, and I would prefer not to use a CURSOR. Any ideas would be appreciated.

    ORGANIZATION TABLE:

    [ORGANIZATION_ID] [int] NOT NULL ,

     [NAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

    HRL TABLE:

    [ORGANIZATION_ID] [int] NOT NULL ,

     [NAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

     

    The Organization table will have listings like:

    Delphi - plant 1, Delphi - plant 2, etc...

    The HRL table will have a listing of 'Delphi' and I need to pull all of the listings from the Organization table that begin with the fields in the HRL table.

     

    I hope this makes sense!

     

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • select * from organization o

    inner join

    hrl h

    on

    o.organization_id = h.organization_id

    where o.name like 'delphi%'







    **ASCII stupid question, get a stupid ANSI !!!**

  • If the id's from the two tables do not match, you may be able to handle it this way: 

    SELECT O.[NAME], HRL.[NAME]

    FROM ORGANIZATION O

       INNER JOIN HRL ON( O.[NAME] LIKE HRL.[NAME] + '%')

    I wasn't born stupid - I had to study.

  • Perfect Farrell! I knew there was a simple way. Thank you!

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply