2012-10-04 23 views
1

表:用户MySql的选择结肠

| 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   | 

当用户登录成功{$用户id = USER_ID,即用户线程的节目标题?

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

这个SQL上述作品时my_threads没有冒号这样的200,217

+1

我不明白。什么是问题? – GolezTrol

回答

1

试试这个:

取代你的结肠逗号

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


SQL fiddle demo

+0

这个SQL给我2(200:1)标题给我(200 + 1)我只需要线程(200)。 – user1710911

+0

@ user1710911:请参阅答案 –

+0

中更新的SQL小提琴感谢您的帮助。但正如你可以看到user_id 100有2个标题200 + 217 sql小提琴只给我1 – user1710911