0

I have two table: table 1: fts virtual table

docid Long auto increase, content Text, (fts column)

table 2: meta data table

docid Long(foreigner key of table1 docid), username Text, timestamp Long

sql: select table1.docid content, username, MAX(timestamp) as time, offsets(table1) from table1, table2 where content Match "a" AND table1.docid = table2.docid group by username order by timestamp desc limit 3;

this sql will not execute, but i delete "group by username", it can execute. why?

4

1 回答 1

0

offsets函数仅适用于 FTS 表,但连接的结果不再是 FTS 表(取决于查询优化器如何决定执行连接)。

您必须分两步进行搜索:

SELECT docid,
       content,
       offsets,
       username,
       MAX(timestamp)
FROM (SELECT docid,
             content,
             offsets(table1) AS offsets
      FROM table1
      WHERE content MATCH 'a')
JOIN table2 USING (docid)
GROUP BY username
ORDER BY timestamp DESC
LIMIT 3;
于 2015-12-02T15:43:13.920 回答