查询不同类型的数据各两条
如果只要其中的A和B中的随便两条的话可以这样子写
select * from
(
select top 2 * from test where t_type='a'
order by id
) a
union all
select * from
(
select top 2 * from test where t_type='b'
order by id
)
select distinct(name)from table
//去掉重复的名字记录
SQL两表查询不重复记录
select t1.bname, t1.btime, t3.aname
from b t1 inner join a t3
on t1.aid = t3.aid
where exists (
select 1 from (
select min(bid) as bid, aid
from b
group by aid) t2
where t1.bid = t2.bid and t1.aid = t2.aid)
order by t1.bid