Skip to content
Advertisement

Filter data in one table based on data in another table

I have two tables presented below. First table contains information about indexes. Each index can be applied to one or more columns. Second table contains set of pairs: table name – column name.

I need to somehow get a list of indexes from table #1 applied to columns from table #2. Result should include all columns for filtered indexes (see result table below).

Can I do that per one “SELECT” operation without using additional table? If so, how?

Advertisement

Answer

A direct JOIN or EXISTS won’t cut it, since you want to display a set (a complete index) if at least one of it’s rows satisfies a condition.

You need to first determine which indexes match against the other table and then display all it’s rows:

Or with EXISTS:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement