Ahmed Salem Ahmed Salem - 1 month ago 8
MySQL Question

MYSQL VB.NET I want to know how to show only duplicated Records

I want to make show only the duplicated rows, and delete all the single rows ( non-dublicated ) in the GridView

My Code Is :

Private Sub load_table()
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=nassa640088;database=testing"
Dim SDA As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource

Try
MysqlConn.Open()
Dim Query As String
Query = "select * from testing.login"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)



MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()

End Try

End Sub

Answer

In that case change your query using group by like (assuming there is an id column)

select * from testing.login where id in (
select id 
from testing.login
group by id
having count(id) > 1 );
Comments