Query is repeating results - Sqlite

Asked

Viewed 58 times

0

I’m making a query in my bd Sqlite, but is returning me some repeated results can not find the error.

 cursor = db.Select(DataBaseHandler.TABLE_OS + " LEFT JOIN " + DataBaseHandler.TABLE_SITUACAO + " ON " + DataBaseHandler.TABLE_SITUACAO + "." + DataBaseHandler.KEY_SITUACAO_ID + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_SITUACAO +
                            " LEFT JOIN " + DataBaseHandler.TABLE_CLIENTES + " ON " + DataBaseHandler.TABLE_CLIENTES + "." + DataBaseHandler.KEY_CLIENTES_ID + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_CLIENTE +
                            " LEFT JOIN " + DataBaseHandler.TABLE_FINANCEIRO + " ON " + DataBaseHandler.TABLE_FINANCEIRO + "." + DataBaseHandler.KEY_FINANCEIRO_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA +
                            " LEFT JOIN " + DataBaseHandler.TABLE_SERVICOS + " ON " + DataBaseHandler.TABLE_SERVICOS + "." + DataBaseHandler.KEY_SERVICO_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA +
                            " LEFT JOIN " + DataBaseHandler.TABLE_PECAS_OS + " ON " + DataBaseHandler.TABLE_PECAS_OS + "." + DataBaseHandler.KEY_PECAS_OS_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA,

                    null, null, null, null, null, DataBaseHandler.KEY_OS_ID_SEQUENCIA + " DESC", null);
  • 2

    Maybe you need some "group by" in your query. Have you checked this?

  • @Can you please give me an example from the code I posted?

1 answer

0


I solved the problem using the INSTINCT clause

 cursor = db.Select(DataBaseHandler.TABLE_OS + " LEFT JOIN " + DataBaseHandler.TABLE_SITUACAO + " ON " + DataBaseHandler.TABLE_SITUACAO + "." + DataBaseHandler.KEY_SITUACAO_ID + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_SITUACAO +
                        " LEFT JOIN " + DataBaseHandler.TABLE_CLIENTES + " ON " + DataBaseHandler.TABLE_CLIENTES + "." + DataBaseHandler.KEY_CLIENTES_ID + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_CLIENTE +
                        " LEFT JOIN " + DataBaseHandler.TABLE_FINANCEIRO + " ON " + DataBaseHandler.TABLE_FINANCEIRO + "." + DataBaseHandler.KEY_FINANCEIRO_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA +
                        " LEFT JOIN " + DataBaseHandler.TABLE_SERVICOS + " ON " + DataBaseHandler.TABLE_SERVICOS + "." + DataBaseHandler.KEY_SERVICO_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA +
                        " LEFT JOIN " + DataBaseHandler.TABLE_PECAS_OS + " ON " + DataBaseHandler.TABLE_PECAS_OS + "." + DataBaseHandler.KEY_PECAS_OS_ID_OS + "=" + DataBaseHandler.TABLE_OS + "." + DataBaseHandler.KEY_OS_ID_SEQUENCIA,

                new String[]{"INSTINCT "+DataBaseHandler.KEY_OS_ID_SEQUENCIA}, null, null, null, null, DataBaseHandler.KEY_OS_ID_SEQUENCIA + " DESC", null);
  • @acklay will consider your response It was the safest practice. After several tests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.