Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

got_r00t?

[Resolvido] SQL Select, nao retornar repetidos.

Recommended Posts

got_r00t?

Boas,

Gostava de saber se ah algum tipo de comando que quando estamos a fazer select a uma BD, para ele não retornar mais que um valor, se esse for repetido.

Cumprimentos

Share this post


Link to post
Share on other sites
got_r00t?

OMG, so mesmo estúpido em não ter vindo aqui mais cedo!

Tipo, aqui esta o codigo que eu tava a escrever, para fazer esse tal de Distinct (e ainda contem erros).

            Dim num_array_1 As Integer = 0
            Dim num_array_2 As Integer = 0
            Dim num_array_3 As Integer = 0
            Dim num_array_max_1 As Integer = 0
            Dim num_array_max_2 As Integer = 0
            Dim num_array_max_3 As Integer = 0
            Dim array_nv_sms(10000) As String
            Dim array_sp(10000) As String
            Dim add_id As String = "Sim"
            Dim command6 As New SqlCommand("SELECT de FROM sms WHERE para=@para AND visto='Nao'", connection_act)
            command6.Parameters.AddWithValue("@para", login_txt.Text)
            connection_act.Open()
            Dim reader6_act As SqlDataReader = command6.ExecuteReader()
            novas_sms_list.Items.Clear()
            While reader6_act.Read()
                array_nv_sms(num_array_1) = reader6_act("de")
                num_array_1 = num_array_1 + 1
                num_array_max_1 = num_array_max_1 + 1
            End While
            num_array_1 = 0
            For i As Integer = 0 To num_array_max_1
                For i2 As Integer = 0 To num_array_max_2
                    If array_nv_sms(num_array_1) = array_sp(num_array_2) Then
                        add_id = "Nao"
                    End If
                    num_array_2 = num_array_2 + 1
                Next
                If add_id = "Sim" Then
                    array_sp(num_array_1) = array_nv_sms(num_array_3)
                    num_array_3 = num_array_3 + 1
                    num_array_max_3 = num_array_max_3 + 1
                End If
                add_id = "Sim"
                num_array_2 = 0
                num_array_max_2 = num_array_max_2 + 1
                num_array_1 = num_array_1 + 1
            Next
            num_array_3 = 0
            For i3 As Integer = 0 To num_array_max_3 - 1
                novas_sms_list.Items.Add(array_sp(num_array_3))
                num_array_3 = num_array_3 + 1
            Next
            reader6_act.Close()
            connection_act.Close()

e aqui o código a fazer a msm coisa, na perfeição :O

        Dim command6 As New SqlCommand("SELECT DISTINCT de FROM sms WHERE para=@para AND visto='Nao'", connection_act)
        command6.Parameters.AddWithValue("@para", login_txt.Text)
        connection_act.Open()
        Dim reader6_act As SqlDataReader = command6.ExecuteReader()
        novas_sms_list.Items.Clear()
        While reader6_act.Read()
            novas_sms_list.Items.Add(reader6_act("de"))
        End While
        reader6_act.Close()
        connection_act.Close()

muito obrigado

Problema resolvido ;P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.