Title: Retrieve two data ID using only one condition
Tags: mysql;sql;asp.net;vb.net;for-loop
Question: I have this program that 'should' retrieve two data ID using only one condition.

This is my code. Thanks.

```Dim coys As String() = {"COY = 'A' AND COY = 'B'", "COY = 'C' AND COY = 'D'", "COY = 'E' AND COY = 'F'", "COY = 'G' AND COY = 'H'"}
    Dim sec As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", _
                            "U", "V", "W", "X", "Y", "Z", "A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2", "I2", "J2", "K2", "L2", _
                            "M2", "N2", "O2", "P2", "Q2", "R2", "S2", "T2", "U2", "V2", "W2", "X2", "Y2", "Z2"}



For x As Integer = 0 To coys.Length - 1
        cn.Open()
        Dim cmd As String = "SELECT a1, a2 a3, COY FROM AA WHERE " &amp; coys(x) &amp; " AND a5 = '" &amp; class2.SelectedValue &amp; "' ORDER BY COY, a2"
        Dim adp As SqlDataAdapter = New SqlDataAdapter(cmd, cn)
        adp.Fill(dt)
        GridView2.DataSource = dt
        GridView2.DataBind()
        cn.Close()
        Dim cnt As Integer = dt.Rows.Count
        For i As Integer = 0 To numsec2.SelectedValue - 1
            Dim vHeader As String = sec(i)
            If Not dt.Columns.Contains(vHeader) Then
                Dim f As New Data.DataColumn(vHeader, GetType(System.String))
                dt.Columns.Add(f)
                f.AllowDBNull = True
            End If
        Next
    Next
```

If I use OR in the coys() array it shows all of the data without acknowledging the second condition, and if I use AND in the coys() array it does not work.


Here is the accepted answer: Use the ```OR``` condition and put it in ```()```, in this way it will honor the second condition:

```Dim coys As String() = {"(COY = 'A' OR COY = 'B')", "(COY = 'C' OR COY = 'D')", "(COY = 'E' OR COY = 'F')", "(COY = 'G' OR COY = 'H')"}
```



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:12/03/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<mysql><sql><asp.net><vb.net><for-loop>', 'Title': 'Retrieve two data ID using only one condition', 'ViewCount': 52, 'id': 27262186, 'user_AboutMe': '<p>Web Developer \nAdvance Programmer on using HTML, PHP, WordPress and ASP.NET (c# and vb)</p>\n', 'user_AccountId': 5380940.0, 'user_DisplayName': 'zref', 'user_Reputation': 37.0, 'user_Views': 21.0, 'user_id': 4286161.0}}