1

表:用户

| user_Id  | my_threads          |               
| 100      | 200:1, 201:2, 217:4 |
| 101      | 200:1, 215:3, 217:4 |

表:螺纹

| thread_id | author_id | title                     |
| 217       | 100       | This is title thread      |
| 200       | 101       | this is only test         |

当用户登录成功 $userId=user_Id 时,显示该用户线程的标题?

select title 
from thread
where FIND_IN_SET(thread.thread_id,(select my_threads from user where user_id=100));

当 my_threads 没有像这样的冒号 200、217 时,上面的这个 sql 有效

4

1 回答 1

1

试试这个:

将冒号替换为逗号

select title 
from thread
where FIND_IN_SET(thread.thread_id,
        (select replace(replace(my_threads,':',','),' ','') from user where user_id=100))


SQL小提琴演示

于 2012-10-04T07:39:53.590 回答