Union on two tables with a where clause in the one

我是研究僧i 提交于 2019-12-04 17:20:22

Not sure if I'm understanding what you want exactly. If you create records in the production table once they have signed up from the temp table, and you only want people who haven't signed up...you don't need to look in the production table at all. Simply:

SELECT recno, name FROM temp WHERE signup='N'

Or however you're trying to limit your search. If for some reason you do need a union but you're trying to eliminate duplicates you'd have to modify your statement to remove the ALL clause. Union ALL causes you to get duplicates. If you don't want duplicate values, you want to not use ALL in your UNION. You can read up on Unions here.

Matt

For what you are asking, you could do it this style.

SELECT * FROM
(
    SELECT '1' as `col`
    UNION 
    SELECT '2' as `col`
) as `someAlias`
where `someAlias`.`col` = '1'

Put the entire union inside parenthesis, give it an alias, then give the condition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!