mysql 多表查询 like_MYSQL多表联合查询的问题
總共有三個(gè)表
post表:id,title,content
terms表:id,name
rela表:postid,termid
post表保存文章內(nèi)容(文章ID、文章標(biāo)題、文章內(nèi)容),terms表保存分類內(nèi)容(分類ID、分類名稱),rela表保存的是文章分類信息,也就是文章ID對(duì)應(yīng)的分類ID。
單純匹配post表的title和content我知道是這樣
query(
"
SELECT id, title
FROM post
WHERE (
`title` LIKE '%關(guān)鍵詞%'
OR `content` LIKE '%關(guān)鍵詞%'
)
LIMIT 0 , 30
"
);
現(xiàn)在也要匹配相應(yīng)的terms表的name,請(qǐng)問(wèn)怎么寫(xiě)呢?
回復(fù)內(nèi)容:
總共有三個(gè)表
post表:id,title,content
terms表:id,name
rela表:postid,termid
post表保存文章內(nèi)容(文章ID、文章標(biāo)題、文章內(nèi)容),terms表保存分類內(nèi)容(分類ID、分類名稱),rela表保存的是文章分類信息,也就是文章ID對(duì)應(yīng)的分類ID。
單純匹配post表的title和content我知道是這樣
query(
"
SELECT id, title
FROM post
WHERE (
`title` LIKE '%關(guān)鍵詞%'
OR `content` LIKE '%關(guān)鍵詞%'
)
LIMIT 0 , 30
"
);
現(xiàn)在也要匹配相應(yīng)的terms表的name,請(qǐng)問(wèn)怎么寫(xiě)呢?
select post.id, post.title from rela left join post on rela.postid = post.id left join terms on rela.termid = terms.id where post.title like '%關(guān)鍵詞%' or post.content like '%關(guān)鍵詞%' or terms.name like '%關(guān)鍵詞%'
聯(lián)合查詢是 Mysql 比較基礎(chǔ)的操作,題主應(yīng)該花點(diǎn)時(shí)間掌握這個(gè)基礎(chǔ)知識(shí)點(diǎn)。:)
本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請(qǐng)注明出處,感謝您的尊重!
總結(jié)
以上是生活随笔為你收集整理的mysql 多表查询 like_MYSQL多表联合查询的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【MySQL联合查询】内连接查询详解
- 下一篇: mysql 数据联合查询语句_MySQL