How do I get only 1 of each value that I'm searching for? 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. 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.
使用DISTINCT关键字:
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT revision FROM revisions_log WHERE revisionName = ? ORDER BY REVISION");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.