总共有三个表post表:id,title,content
terms表:id,name
rela表:postid,termidpost表保存文章内容(文章ID、文章标题、文章内容),terms表保存分类内容(分类ID、分类名称),rela表保存的是文章分类信息,也就是文章ID对应的分类ID。
单纯匹配post表的title和content我知道是这样
query(
"
SELECT id, title
FROM post
WHERE (
`title` LIKE '%关键词%'
OR `content` LIKE '%关键词%'
)
LIMIT 0 , 30
"
);
现在也要匹配相应的terms表的name,请问怎么写呢?
terms表:id,name
rela表:postid,termidpost表保存文章内容(文章ID、文章标题、文章内容),terms表保存分类内容(分类ID、分类名称),rela表保存的是文章分类信息,也就是文章ID对应的分类ID。
单纯匹配post表的title和content我知道是这样
query(
"
SELECT id, title
FROM post
WHERE (
`title` LIKE '%关键词%'
OR `content` LIKE '%关键词%'
)
LIMIT 0 , 30
"
);
现在也要匹配相应的terms表的name,请问怎么写呢?
WHERE (
`title` LIKE '%关键词%'
OR `content` LIKE '%关键词%'
OR terms.name like '%关键词%'
)
WHERE (
a.title LIKE '%关键词%'
OR a.content LIKE '%关键词%'
OR c.name like '%关键词%'
)
and a.id=b.postid
and b.termid=c.id
from post , rela, terms
where post.id=rela.postid
and terms.id=rela.termid
and (`title` LIKE '%关键词%'
OR `content` LIKE '%关键词%')