user1582249
user1582249

Reputation: 11

SQL Select Statement with sub selection

I'm looking for an SQL Select statement that when given a CustomerId = 'AAAAA' will return all rows that have the same RegionId as AAAAA.

Thanks

CustomerId, RegionId

AAAAA,11111  
BBBBB,11111  
CCCCC,22222  
DDDDD,22222

Result required:

AAAAA,11111  
BBBBB,11111

Upvotes: 0

Views: 70

Answers (2)

daryosh setorg
daryosh setorg

Reputation: 126

You can select like this :

SELECT CustomerId, RegionId
FROM Table
WHERE RegionId = (SELECT RegionId FROM Table WHERE CustomerId = 'AAAAA')

Upvotes: 0

sgeddes
sgeddes

Reputation: 62861

There are a couple of ways to do this -- here's one with in:

SELECT CustomerId, RegionId
FROM YourTable
WHERE RegionId IN (
    SELECT RegionId 
    FROM YourTable 
    WHERE CustomerId = 'AAAAA')

Upvotes: 2

Related Questions