开发者

problem in posts category

开发者 https://www.devze.com 2023-03-31 21:42 出处:网络
i ne开发者_开发知识库ed help in sql query i have table named -- threads contain post_id / post_title .....

i ne开发者_开发知识库ed help in sql query

i have table named -- threads

contain

post_id / post_title .....

and i have categories table named

thread_categories

contain

cate_id / post_id

file.php?cate_id=20

i want get all posts in category id = 20

Thank you


I think it's better to store your categories which is related to threads in a separate table. Otherwise your query will very slow and inefficient.

You can use current table structure and try to use the following query but I don't like it:

SELECT * FROM posts 
WHERE FIND_IN_SET(provided_cat_id,REPLACE(thread_categories, '::', ','));

New query:

SELECT * FROM threads t inner join thread_categories tc on t.post_id=tc.post_id
where tc.cate_id=20;


Select * from posts where YourCategoryID in (splitstring('::', thread_categories))

I hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号