Ankit
Ankit

Reputation: 17

How to filter 1 table using other

I have two tables:

TABLE1
----------------
query |  info
aa    |  info
bb    |  info
aa    |  info
cc    |  info
cc    |  info

TABLE2:
----------------
query |  info
aa    |  inf
cc    |  inf

Table 1 can have repeating queries, but 2 cannot

I need an SQL query to get all queries in table 1 that also exist in table 2. If there are multiple corresponding queries in table 1, then there should be multiple in the result What is the simplest way to do this?

Upvotes: 0

Views: 33

Answers (2)

Yogee
Yogee

Reputation: 1462

select table_1.* from table_1 inner join table_2 on table_1.query = table_2.query 

Upvotes: 0

PaulProgrammer
PaulProgrammer

Reputation: 17680

 select * from table1 where table1.query in (select query from table2)

Upvotes: 2

Related Questions