Reputation: 11
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
Reputation: 126
You can select like this :
SELECT CustomerId, RegionId
FROM Table
WHERE RegionId = (SELECT RegionId FROM Table WHERE CustomerId = 'AAAAA')
Upvotes: 0
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