Duplicate entries with HeidiSQL

  • VB.NET

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von INOPIAE.

    Duplicate entries with HeidiSQL

    Hello,
    I am trying to retrieve data from HeidiSQL. In the table M, the rows are mentioned in the code below are occuring 6 times but in the table N they are occuring only 4 times and i wanna join them but i am getting each entry 4 times and i want it only once. Can someone help me? Both have only one common column and that is "Prod_ Order No_"

    VB.NET-Quellcode

    1. Private Sub btnFAübernhmn_Click(sender As Object, e As EventArgs) Handles btnFAübernhmn.Click
    2. If DataGridView1.SelectedCells.Count > 0 Then
    3. Dim rowIndex As Integer = DataGridView1.SelectedCells(0).RowIndex
    4. Dim Prod_OrderNo_ As String = DataGridView1.Rows(rowIndex).Cells(0).Value
    5. 'msg for user to select atleast one row
    6. If String.IsNullOrEmpty(Prod_OrderNo_) Then
    7. MsgBox("Please select a non-empty row.", vbInformation)
    8. Return
    9. End If
    10. ' Open the database connection
    11. OpenNavDB()
    12. ClearDataGridView2()
    13. Dim Erpcmd2 As New SqlCommand
    14. Erpcmd2.Connection = NavDB
    15. 'WHERE dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Routing No_] LIKE '01%' AND dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Status]= 3
    16. 'from database
    17. Erpcmd2.CommandText = "SELECT M.[Operation No_],N.[No_],M.[Qlty Measure Code],M.[Description],M.[Min_ Value],M.[Max_ Value],M.[Mean Tolerance]
    18. FROM dbo.[RPS24$Prod_ Order Rtng Qlty Meas_] M
    19. INNER JOIN dbo.[RPS24$Prod_ Order Routing Line] N ON M.[Prod_ Order No_] = N.[Prod_ Order No_]
    20. where M.[Prod_ Order No_]= @Prod_OrderNo_ AND M.[Status]=N.[Status]
    21. ORDER BY [Operation No_]"

    *Code-BBCode eingefügt*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()

    HeidiSQL is a database access client, not a DBMS. You probably mean something like MSSQL or MySQL.

    Concerning your question: You could change SELECT to SELECT DISTINCT to get only one entry per identical fetched row.
    Besucht auch mein anderes Forum:
    Das Amateurfilm-Forum
    It sounds like you want to create a specific query. If you provide example data, it will be much easier to help you.
    I think you dont clarify sufficiently which rows you want. With 6 rows in M matching one specific ordernumber and 4 results in N matching the same ordernumber and status you should expect to find 24 rows in your resultset.
    You can try creating a fiddle for us, with that we could also easily check for the results ourselves.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Haudruferzappeltnoch“ ()

    SpaceyKevin schrieb:

    FROM dbo.[RPS24$Prod_ Order Rtng Qlty Meas_] M
    INNER JOIN dbo.[RPS24$Prod_ Order Routing Line] N ON M.[Prod_ Order No_] = N.[Prod_ Order No_]
    where M.[Prod_ Order No_]= @Prod_OrderNo_ AND M.[Status]=N.[Status]


    You link the tables two times:
    once in the INNER JOIN M.[Prod_ Order No_] = N.[Prod_ Order No_]
    and once in the WHERE statement M.[Status]=N.[Status]
    NB. Es ist doch schön, wenn man lesbare Namen vergibt. Siehe auch [VB.NET] Beispiele für guten und schlechten Code (Stil).
    Hello, Thank you for your reply. The idea behind it was that a user would select one row from a datagridview1 and click on the button 'btnFAübernhmn' and then the Quality measuring values(Prüfmerkmale) would be shown in another datagridview2.

    The problem I was facing was that all the data needed to show in datagridview2 was present in one table in the database except one data which was in another table so I had to join those two tables.
    For each row there are six (Prüfmerkmale) which are present in the 'M' column and one Merkmale in 'N', now in the 'N' Table this information was mentioned 4 times, but I needed the information for 6 merkmales.

    Explanation in more detail: There are four Arbeitsgang where the quality features of the product are mentioned, eg. During one Arbeitsgang the product has one only quality merkmale to be measured by the user while in the second Arbeitsgang, there are four quality features to be measured. Now in table 'M' there are quality features mentioned i.e 6 and in table 'N' the number of Arbeitsgang is mentioned which I have is 4.
    So I needed each merkmale their corresponding Arbeitsgang number and there I was facing an error.

    But the code I provided is working fine now.




    VB.NET-Quellcode

    1. Private Sub btnFAübernhmn_Click(sender As Object, e As EventArgs) Handles btnFAübernhmn.Click
    2. If DataGridView1.SelectedCells.Count > 0 Then
    3. Dim rowIndex As Integer = DataGridView1.SelectedCells(0).RowIndex
    4. Dim Prod_OrderNo_ As String = DataGridView1.Rows(rowIndex).Cells(0).Value
    5. 'msg for user to select atleast one row
    6. If String.IsNullOrEmpty(Prod_OrderNo_) Then
    7. MsgBox("Please select a non-empty row.", vbInformation)
    8. Return
    9. End If
    10. ' Open the database connection
    11. OpenNavDB()
    12. ClearDataGridView2()
    13. Dim Erpcmd2 As New SqlCommand
    14. Erpcmd2.Connection = NavDB
    15. 'from database
    16. Erpcmd2.CommandText = "SELECT dbo.[RPS24$Prod_ Order Routing Line].[No_], dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Operation No_],
    17. dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Qlty Measure Code], dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Description],
    18. dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Min_ Value], dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Max_ Value], dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Mean Tolerance]
    19. FROM dbo.[RPS24$Prod_ Order Routing Line]
    20. JOIN dbo.[RPS24$Prod_ Order Rtng Qlty Meas_] ON dbo.[RPS24$Prod_ Order Routing Line].[Prod_ Order No_] = dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Prod_ Order No_]
    21. Where dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Status] = dbo.[RPS24$Prod_ Order Routing Line].[Status]
    22. AND dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Operation No_] = dbo.[RPS24$Prod_ Order Routing Line].[Operation No_]
    23. AND dbo.[RPS24$Prod_ Order Routing Line].[Prod_ Order No_] = @Prod_OrderNo_"
    24. 'AND dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Routing No_] LIKE '01%'
    25. Erpcmd2.Parameters.Add("@Prod_OrderNo_", SqlDbType.NVarChar).Value = Prod_OrderNo_
    26. Erpcmd2.Parameters.Add("@Status", SqlDbType.Int).Value = 3
    27. Dim MyErpReader As SqlDataReader
    28. MyErpReader = Erpcmd2.ExecuteReader
    29. If MyErpReader.HasRows Then
    30. While MyErpReader.Read
    31. DataGridView2.Rows.Add(
    32. MyErpReader("No_"),
    33. MyErpReader("Operation No_"),
    34. MyErpReader("Qlty Measure Code"),
    35. MyErpReader("Description"),
    36. Format(MyErpReader("Min_ Value"), "0.000"),
    37. Format(MyErpReader("Max_ Value"), "0.000"),
    38. Format(MyErpReader("Mean Tolerance"), "0.000")
    39. )
    40. End While
    41. 'adjusting values in columns to fit
    42. For Each column As DataGridViewColumn In DataGridView2.Columns
    43. column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    44. Next
    45. Else
    46. MsgBox("It is empty", vbInformation)
    47. End If
    48. NavDB.Close()
    49. End If
    50. End Sub

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()

    You can change your code to this may be it is better to understand:

    SQL-Abfrage

    1. ​FROM dbo.[RPS24$Prod_ Order Routing Line], dbo.[RPS24$Prod_ Order Rtng Qlty Meas_]
    2. WHERE
    3. dbo.[RPS24$Prod_ Order Routing Line].[Prod_ Order No_] = dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Prod_ Order No_] AND
    4. dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Status] = dbo.[RPS24$Prod_ Order Routing Line].[Status] AND
    5. dbo.[RPS24$Prod_ Order Rtng Qlty Meas_].[Operation No_] = dbo.[RPS24$Prod_ Order Routing Line].[Operation No_] AND
    6. dbo.[RPS24$Prod_ Order Routing Line].[Prod_ Order No_] = @Prod_OrderNo_"
    NB. Es ist doch schön, wenn man lesbare Namen vergibt. Siehe auch [VB.NET] Beispiele für guten und schlechten Code (Stil).