title: How to avoid fetching double data from sqlite in a spinner?
body: <p>I'm trying to fetch data from sqlite to set them into a spinner. The user creates rows of travel dates and set them into the database (COLUMN_DATE_DEPART).
  In the first spinner I'd like to get the list of the years existing in the COLUMN_DATE_DEPART.
  In the second one, I'd like to get the list of months of the year selected in the first spinner.</p>
  
  <p>The problem is as followed: In the first spinner i get the years as expected. In the second spinner i get the months but in double so that if the user created two travels on the 1st and the 31st of January, I'll have the month January twice rather than once.</p>
  
  <p>My question is: What did i miss ?</p>
  
  <p>Find attached my code.</p>
  
  <p><strong>Fragment Activity Java</strong></p>
  
  <pre><code>List&lt;String&gt; an = helper.ListeAnneeTrajet(et_iduser);
                  final ArrayAdapter&lt;String&gt; adapterA= new ArrayAdapter&lt;&gt;(this.getActivity(), R.layout.spinner_item, an);
                  adapterA.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                  annee.setAdapter(adapterA);
                  annee.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
                      @Override
                      public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) {
  
                          List&lt;String&gt; mo = helper.ListeMoisTrajet(et_iduser, annee.getSelectedItem().toString().trim());
                          ArrayAdapter&lt;String&gt; adapterB = new ArrayAdapter&lt;&gt;(getActivity(), R.layout.spinner_item, mo);
                          adapterA.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                          mois.setAdapter(adapterB);
                          mois.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
                              @Override
                              public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) {
                                  // your code here
                              }
                              @Override
                              public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
                                  // your code here
                              }
                          });
                      }
                      @Override
                      public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
                          // your code here
                      }
                  });
  </code></pre>
  
  <p><strong>DatabaseHelper</strong></p>
  
  <pre><code>public List&lt;String&gt; ListeAnneeTrajet(String et_iduser) {
          List&lt;String&gt; an = new ArrayList&lt;&gt;();
          String selectQuery = "SELECT DISTINCT * FROM " + TABLE_NAME3 + " WHERE (" + COLUMN_ID_CHAUFFEUR + " = '" + et_iduser + "' AND " + COLUMN_DATE_DEPART + " &gt;= DATE('NOW')) GROUP BY SUBSTR(" + COLUMN_DATE_DEPART + ",1,4) ORDER BY " + COLUMN_DATE_DEPART + " ASC";
          db = this.getReadableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          if (cursor.moveToFirst()) {
              do {
                  an.add(cursor.getString(cursor.getColumnIndex(COLUMN_DATE_DEPART)).substring(0,4));
              }
              while (cursor.moveToNext());
          }
          cursor.close();
          db.close();
          return an;
      }
  
      public List&lt;String&gt; ListeMoisTrajet(String et_iduser, String et_annee) {
          List&lt;String&gt; mo = new ArrayList&lt;&gt;();
          String selectQuery = "SELECT DISTINCT * FROM " + TABLE_NAME3 + " WHERE (" + COLUMN_ID_CHAUFFEUR + " = '" + et_iduser + "' AND " + COLUMN_DATE_DEPART + " &gt;= DATE('NOW') AND SUBSTR(" + COLUMN_DATE_DEPART + ",1,4) = '" + et_annee + "') GROUP BY SUBSTR(" + COLUMN_DATE_DEPART + ",6,7) ORDER BY " + COLUMN_DATE_DEPART + " ASC";
          db = this.getReadableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
  
          if (cursor.moveToFirst()) {
              do {
                  mo.add(cursor.getString(cursor.getColumnIndex(COLUMN_DATE_DEPART)).substring(5,7));
              } while (cursor.moveToNext());
          }
          cursor.close();
          db.close();
          return mo;
      }
  </code></pre>