I used the following code to select unique values from the database
myCommand = New SqlCommand("SELECT DISCTINCT Visitor, BookCode FROM tblBook", myConnection)
myAdapte开发者_Python百科r = New SqlDataAdapter(myCommand)
myAdapter.Fill(myDataSet, "tblBook")
cboAuthor.DataSource = myDataSet.Tables(0)
cboAuthor.DisplayMember = "Author"
cboAuthor.ValueMember = "BookCode"
And it does not retrieve the unique values, it remains the same. But if I use only SELECT DISTINCT Author FROM
tblBook it works fine.
Please help.
SELECT DISTINCT
will ensure that no duplicate records are returned in the result set.
Therefore if you only put SELECT DISTINCT Author, you will get a list of unique authors.
Putting SELECT DISTINCT Author, Visitor, BookCode
may return duplicate authors, with different visitor or bookcode.
SELECT DISTINCT would get all distinct values of ALL fields.
everything is right. select DISTINCT returns all unique combinations of all fields that are in SELECT clause.
精彩评论