现在我有两个表,表1和表2,表2是表1的外键表
我要表链接查询,查询表1的数据不重复!比如:
表1
id name
1 陈
表2
Tid id servicename
1 1 服务1
2 1 服务2
如果是怎样查询是有两条数据的,我怎样去掉重复的
select a.* from 表1 a left join 表2 b on a.id=b.id
where b.servicename like '%服务%'
group by或者distinct
是不是表1在表2中有记录?是像下面这样的效果吗?
select a.* from 表1 a where a.id in(select id from 表2 where servicename like '%服务%')
加 select distinct
select *
from 表1 a
where exists (select 1 from 表2 where id=a.id and servicename like '%服务%')