-
开心每一天1111
看不到你写的代码,只好猜测一下:sql="select * from (select 1 as b, data.* from data WHERE name Like '哈哈' union select 2 as b, data.* from data where name Like '%"& 变量 &"%' or tag Like '哈哈') order by b asc"改成sql="select * from(select 1 as b, data.*from dataWHEREname Like '哈哈'and name not Like '%"& 变量 &"%'and tag not Like '哈哈'unionselect 2 as b, data.*from datawherename not like'哈哈'and (name Like '%"& 变量 &"%' or tag Like '哈哈'))order by b asc"想法就是:两个select语句自己选满足自己条件的记录,同时,去除另一个select语句选出的记录
-
蛊毒传说
你的结果集第一个前面加了个一 第二个前面加了个2 那样肯定不重复了比如从第一个查询返回1 a b c1 b c d从第二个查询返回2 a b c2 b c d顺便问一下你要前面的1,2有什么用 去掉不就好了吗?
-
幕布斯7119047
drop table test1;drop table test2;create table test1 (a char(4),c char(4));create table test2 (a char(4),c char(4));insert into test1 values('aaa','bbb')insert into test1 values('aaa','aaa')insert into test2 values('ccc','aaa')insert into test2 values('aaa','aaa')select 1 as b,* from test1 where a like 'aaa'union select 2 as b,* from test2 where c like 'aaa'order by b这个就是你那条语句,返回结果为1 aaa aaa1 aaa bbb2 aaa aaa2 ccc aaa先在去除重复的范围内选取,举例如下:select 1 as b,* from test1 where a like 'aaa'union select 2 as b,* from test2 where c like 'aaa' and (a+c) not in (select a+c from test1)order by b返回结果:1 aaa aaa1 aaa bbb2 ccc aaa具体怎么改你的语句,根据实际情况来。我这个例子简单,就是用(a+c) not in (select a+c from test1)说明一下去除重复的范围。
-
婷婷同学_
sql="select distinct * from (select 1 as b, data.* from data WHERE name Like '哈哈') union (select 2 as b, data.* from data where name Like '%"& 变量 &"%' or tag Like '哈哈') order by b asc"