Get an item from each Row

0

How can I get an Item from each Row?

For example, I have a column with the following Rows:

  • TEST
  • TEST
  • TEST2
  • TEST2
  • TEST3

As I wanted:

  • TEST
  • TEST2
  • TEST3

My code:

public void carregar(){
        qy = "SELECT TESTEROWS FROM COLUNA";
        try {
            PreparedStatement ps = MySQL.getConn().prepareStatement(qy);
            ResultSet rs = ps.executeQuery();
            if (rs.next()){
                setItem(TypeItem.valueOf(rs.getString("Type")));
            }
            loadItemsLoja();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

With while it's only returning all (obvious), with if it only returns me the first one. How can I get one from each Row?

    
asked by anonymous 27.09.2018 / 19:43

2 answers

1

Only use SQL SELECT DISTINCT Statement

SELECT distinct(TESTEROWS) FROM COLUNA

    
27.09.2018 / 19:47
0

There are two ways to do this:

SELECT distinct TESTEROWS FROM COLUNA

or

SELECT TESTEROWS FROM COLUNA group by TESTEROWS
    
27.09.2018 / 19:50