开发者

vb.net - select distinct not get the result wanted

开发者 https://www.devze.com 2023-03-16 23:55 出处:网络
I used the following code to select unique values from the database myCommand = New SqlCommand(\"SELECT DISCTINCT Visitor, BookCode FROM tblBook\", myConnection)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消