Frink
Frink

Reputation: 221

Filter table with any value from other table column

How to write select in oracle to filter value in one table with any value from other table column.

To be clear, I have two table. For Example Car and Colors.

In Car table I have two columns, car_model and car_color, in Colors table I have col_code and col_color columns.

I need to select all car_model where car_color = any color from col_color column from colors table.

Something like pseudo:

Select car_model From car Where car_color = color.col_color

Upvotes: 0

Views: 2664

Answers (2)

AndreySarafanov
AndreySarafanov

Reputation: 804

I don't think you need any joins, it is the unintuitive way to write your query.

select car_model
from car
where car_color in (select col_color from color)

Upvotes: 3

Alexey Malev
Alexey Malev

Reputation: 6531

You can use join (acually, outer join) like this:

select car.car_model, color.col_color from car left join color on car.car_color = color.col_code

Or, if you like it more,

select car.car_model, color.col_color from car, color where car.car_color = color.col_code

which is actually inner joins tables. You may find information on different types of joins in Wikipedia.

Upvotes: 1

Related Questions