SQL multiple columns in IN clause

后端 未结 6 2001
情书的邮戳
情书的邮戳 2020-11-27 04:15

If we need to query a table based on some set of values for a given column, we can simply use the IN clause.

But if query need to be performed based on multiple col

6条回答
  •  北海茫月
    2020-11-27 04:54

    In general you can easily write the Where-Condition like this:

    select * from tab1
    where (col1, col2) in (select col1, col2 from tab2)
    

    Note
    Oracle ignores rows where one or more of the selected columns is NULL. In these cases you probably want to make use of the NVL-Funktion to map NULL to a special value (that should not be in the values):

    select * from tab1
    where (col1, NVL(col2, '---') in (select col1, NVL(col2, '---') from tab2)
    

    oracle sql

提交回复
热议问题