How to check if a given data exists in multiple tables (all of which has the same column)?

后端 未结 6 1207
眼角桃花
眼角桃花 2020-12-06 05:48

I have 3 tables, each consisting of a column called username. On the registration part, I need to check that the requested username is new and unique.

I need that si

6条回答
  •  臣服心动
    2020-12-06 06:39

    select 1 
    from (
        select username as username from tbl1
        union all
        select username from tbl2
        union all
        select username from tbl3
    ) a
    where username = 'someuser'
    

提交回复
热议问题