Marian Pavel
Marian Pavel

Reputation: 2876

Select from Table A Rows that Contain Value from Column from Table B

I want to SELECT from TABLE A all rows that Have Values from Table B Column 1.

Example:

Table A:
Name | AGE
Name1 19
Name2 50
Name3 50
Name4 51

Table B:
NAME | AnotherColumn
Name1 | ...
Name2 | ...

The result should be:

Name1
Name2

So Far I succeed to make the query but when I try to reffer on Value from Table B in the column it asks me to promnt that value.

Upvotes: 0

Views: 559

Answers (1)

M.Ali
M.Ali

Reputation: 69524

SELECT A.Name
FROM TableA A
WHERE EXISTS (SELECT 1
              FROM TableB
              WHERE A.Name = TableB.Name)

OR

SELECT A.Name 
FROM TableA A 
INNER JOIN TableB B ON A.Name = B.Name

Upvotes: 1

Related Questions