select a from tablename where a in ('MO-01-02-01c')
union all select a from tablename where a not in ('MO-01-02-01c') order by a
执行后a的'MO-01-02-01c'这个值不见了.. 怎么回事???
union all select a from tablename where a not in ('MO-01-02-01c') order by a
执行后a的'MO-01-02-01c'这个值不见了.. 怎么回事???
--try:
select a from tablename where a in ('MO-01-02-01c')
union all
select * from (select a from tablename where a not in ('MO-01-02-01c'))a
order by a
什么意思?
declare @t table(a nvarchar(20))
insert @t select 'MO-01-02-01c'
insert @t select 'MO-01-02-01d'
insert @t select 'MO-01-02-01e'
insert @t select 'MO-01-02-01f'
insert @t select 'MO-01-02-01g'
select a from @t where a in (N'MO-01-02-01c')
union all
select a from @t where a not in (N'MO-01-02-01c') order by a
/*
a
--------------------
MO-01-02-01c
MO-01-02-01d
MO-01-02-01e
MO-01-02-01f
MO-01-02-01g(5 個資料列受到影響)*/
select a from tablename where a not in ('MO-01-02-01c')
union all select a from tablename where a in ('MO-01-02-01c') order by a
就是没有了 . 本来'MO-01-02-01c'这个值 是要查出来的 就是现在查询结果里面 没这个值了
union all select a from tablename where a in ('MO-01-02-01c') order by a
就是没有了 . 本来'MO-01-02-01c'这个值 是要查出来的 就是现在查询结果里面 没这个值了
是这句话... 要的就是一起执行啊..!
select a from tablename where a in ('MO-01-02-01c')
看看是否确定有记录
--看是不是数据中存在空格,这样:
select a from tablename where replace(a,' ','') in ('MO-01-02-01c')
union all select a from tablename where replace(a,' ','') not in ('MO-01-02-01c') order by a
我这句话的意思是 先不给他排序 排序后再给它显示出来在原来的位置
select a from tablename where a in ('MO-01-02-01c')
union all select a from tablename where a not in ('MO-01-02-01c') order by a
这句话 order by a之所以放在下面 是因为放在上面 会报union 有语法错误
select a from
(select a,px=0 from tablename where a in ('MO-01-02-01c')
union all
select a,px=1 from tablename where a not in ('MO-01-02-01c'))a
order by px,a
union all select a from tablename where a not in ('MO-01-02-01c') 问下 这样行么??? 为什么不行?
union all时,排序只能在最后,语法问题。