简体   繁体   English

如何选择每个唯一值之一?

[英]How to Select 1 of Each Unique Value?

How do I get only 1 of each value that I'm searching for? 我如何只获取要搜索的每个值中的1个? This is what I have so far ... 这是我到目前为止所拥有的...

    public String getRevisionsLog(String revName) {
    try {
        String txt = "\t\t\t\t\t\t\t#e---===Revision Logs===---#n\r\n";
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT revision FROM revisions_log WHERE revisionName = ? ORDER BY REVISION");
        ps.setString(1,  revName);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            txt += rs.getString("revision") + "\r\n";
        }
        ps.close();
        rs.close();
        return txt;
    } catch (Exception e) {

    }
    return "No logs were found!";
}

So far in my database I have rows of values that have a revision value of 1 and 1.1. 到目前为止,在数据库中,我有几行值的修订版值为1和1.1。 I want to retrieve those revision numbers, but only once of each. 我想检索那些修订号,但每个只能检索一次。 If I have for say ... 如果我有话要说...

1, 1, 1, 1.1, 1.1, 1.1

I only want to retrieve 1 and 1.1, and not all the instances of 1. 我只想检索1和1.1,而不是1的所有实例。

使用DISTINCT关键字:

    PreparedStatement ps = con.prepareStatement("SELECT DISTINCT revision FROM revisions_log WHERE revisionName = ? ORDER BY REVISION");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM