- 论坛徽章:
- 0
|
a表
id b_id c_id data
1 1 1 hello
2 1 4 world
3 3 2 sqlserver
4 2 2 mysql
5 2 1 hello
6 3 1 hello
7 3 3 2005
b表
id class
1 test1
2 test2
3 test2
c表
id style
1 0
2 1
3 0
4 1
想要的结果是,搜hello,出来如下结果
a.b_id a.data b.class
1 world test1
2 mysql test2
3 sqlserver test2
我的应用场合是这样的:我有如下3条数据
hello world
hello sqlserver 2005
hello mysql
可是放到一张表里面去了,而搜索的结果依然想保持原来的条目关系
效果应该是等同下面SQL语句
select a.b_id, a.data, b.class from a left join b on a.b_id=b.id
where 1=1
and b_id in (
select b_id
from a
where data like 'hello'
)
and exists (select 1 from c where a.c_id = c.id AND c.style = 1)
|
不过这里面用了子查询,而mysql不支持子查询,该怎么写SQL语句呢? |
|