0
query = "SELECT" +
            " e.id AS _id," +
            " ke.id AS ke_id," +
            " ke.fk as ke_fk," +
            " ke.value as ke_value," +
            " re.id AS ke_id," +
            " re.fk as re_fk," +
            " re.value as re_value," +
            " s.id AS  s_id," +
            " s.fk as s_fk," +
            " g.id AS g_id," +
            " g.fk as g_fk," +
            " g.lang," +
            " g.value as g_value" +
            " FROM entry e" +
            "     INNER JOIN k_ele ke ON e.id = ke.fk" +
            "     INNER JOIN r_ele re ON e.id = re.fk" +
            "     INNER JOIN sense s ON e.id = s.fk" +
            "     INNER JOIN gloss g ON s.id = g.fk" +
            " WHERE g.value like '%"+lookingFor+"%' LIMIT 20";

我有桌子'光泽'。我在“价值”中有列。它是连接表中的“g_value”。例如,当我搜索“女孩”时,它发现了五个重复的结果。

在此处输入图像描述

如何取'g_value'的不同值以避免结果重复?

4

1 回答 1

0

我认为您想通过使用 GROUP BY 来消除重复项。像这样:

query = "SELECT" +
            " e.id AS _id," +
            " ke.id AS ke_id," +
            " ke.fk as ke_fk," +
            " ke.value as ke_value," +
            " re.id AS ke_id," +
            " re.fk as re_fk," +
            " re.value as re_value," +
            " s.id AS  s_id," +
            " s.fk as s_fk," +
            " g.id AS g_id," +
            " g.fk as g_fk," +
            " g.lang," +
            " g.value as g_value" +
            " FROM entry e" +
            "     INNER JOIN k_ele ke ON e.id = ke.fk" +
            "     INNER JOIN r_ele re ON e.id = re.fk" +
            "     INNER JOIN sense s ON e.id = s.fk" +
            "     INNER JOIN gloss g ON s.id = g.fk" +
            " WHERE g.value like '%"+lookingFor+"%' " +
            " GROUP BY " +
            " LIMIT 20";
于 2013-08-12T06:25:46.220 回答