所以 - 我有 2 张桌子:
entries
桌子:
id - Primary key
meta_keys VARCHAR 20
meta_desc VARCHAR 20
..some other unimportant columns...
headwords
桌子:
id - Primary key
fk_entries_id - foreign key refers to entries(id)
headword_text VARCHAR(200)
..some other unimportant columns...
所以条目可能有多个词条 - 对。所以我只是想对词条中包含特定单词的条目进行分页。我想出的唯一查询需要 LEFT JOIN 然后 LIKE 并且有点慢。
SELECT entries.*, GROUP_CONCAT(DISTINCT headwords.headword_text SEPARATOR ' ') AS hw
FROM entries
LEFT JOIN headwords ON (entries.id = headwords.fk_entries_id)
GROUP BY entries.id
HAVING hw LIKE '%dog%'
LIMIT 20,20;
寻求建议以加快这种方法。
编辑>等待 - 这是一个错误的查询吗?:
SELECT entries.id, GROUP_CONCAT(DISTINCT headwords.headword_text SEPARATOR ' ') AS hw
FROM entries
LEFT JOIN headwords
ON (entries.id = headwords.fk_entries_id)
WHERE headwords.headword_text LIKE 'dog%'
GROUP BY entries.id;