SQL how to compare two columns from two different tables

后端 未结 6 1647
无人共我
无人共我 2021-01-02 16:24

I have two tables, in which table 1 contains 4 columns while table 2 contains 8 columns. I have two columns in table1 that I want to compare them with two columns in table2.

6条回答
  •  日久生厌
    2021-01-02 16:49

    The query with the least comparisions I can think of is

    Select t1.* 
    from table1 t1
    left join table2 t2 on t1.column1 in (t2.column6, t2.column7)
                        or t1.column2 in (t2.column6, t2.column7)
    where t2.column6 is null
    

提交回复
热议问题