Tag Archives: union

SQL 的 union 的作法

The UNION query allows you to combine the result sets of 2 or more “select” queries. It removes duplicate rows between the various “select” statements.

select count(1) from (
      — 賣家
      select ctrl_rowid
      from bidleader.sold_record s
      where s.ctrl_date like ‘200701%’
      group by ctrl_rowid
      union
      — 買家
      select p_ctrl_rowid  ctrl_rowid
      from bidleader.sold_record s
      where s.ctrl_date like ‘200701%’
      group by p_ctrl_rowid
) t