Creating query that returns id if condition is matched in rows from two tables

前端 未结 4 495
忘了有多久
忘了有多久 2021-02-03 14:11

I\'m learning SQL/dbms and using Postgres. I want to return rows that both have a certain value in a certain column. For example in tables Carpets and Curtain

4条回答
  •  暖寄归人
    2021-02-03 15:08

    Since the results are for two disjoint tables, you actually want a union instead:

    select id, 'curtains' as source from curtains where color = 'lightyellow'
      union 
    select id, 'carpets' as source from carpets where color = 'lightyellow'
    

    Regarding joins, learn them all together. They are just slight variations of each other.

提交回复
热议问题