110,533
社区成员
发帖
与我相关
我的任务
分享
with t1(id, name, othername, message) as
(
select 1 ,'a','b','m' union all
select 2 ,'a','c','m' union all
select 3 ,'b','a','m' union all
select 4 ,'c','c','m' union all
select 5 ,'e','a','m' union all
select 6 ,'f','a','m' union all
select 7 ,'c','a','m' union all
select 8 ,'a','b','m'
)
select * from t1 where (name='a' or othername='a')
and not exists(
select 1 from t1 t2
where ((t1.name='a' and t1.othername=t2.name)
or (t1.othername='a' and t1.name=t2.othername))
and t2.id<t1.id
)
var result = lst.Where(a => a.Name == "a" || a.OtherName == "a").GroupBy(a => string.Concat((a.Name + a.OtherName).OrderBy(c => c))).Select(a => a.First());
select top 1 *
from table
where name='a' or othername='a'
order by id asc