有三张表。
第一张,post 表
id
title
第二张 map 表
id
pid // post.id
tagid // tag.id第三张 tag 表
id
title一个post 有多个tag,对应关系存在map表中。我现在要通过post id 找到和它有相同tag 的其他post 。
我现在写的sql如下:
select * from post where id in (
select pid frome map where tid in (
select tid frome map where pid = 98
)
)这样写有问题吗?我在执行的时候,得不到结果,貌似数据库直接跟我断开连接了,没有响应。不知道描述得是否清楚。
第一张,post 表
id
title
第二张 map 表
id
pid // post.id
tagid // tag.id第三张 tag 表
id
title一个post 有多个tag,对应关系存在map表中。我现在要通过post id 找到和它有相同tag 的其他post 。
我现在写的sql如下:
select * from post where id in (
select pid frome map where tid in (
select tid frome map where pid = 98
)
)这样写有问题吗?我在执行的时候,得不到结果,貌似数据库直接跟我断开连接了,没有响应。不知道描述得是否清楚。
from post A,map B,tag C
where A.id=B.pid and B.tagid=C.id and C.id=98