我的表中内容如下:
u_name   u_sex   u_born  u_group
11        男      1985    A
12        女      1985    B
11        男      1984    A
添加记录的时候u_name\u_born肯定有重复的,
但是我想在读取的时候,把重复的过滤掉而且一次我要读取u_name和u_born这两列,用一条SQL语句,然后填充到ComboBox中,
请问这个SQL语句该怎么写呀?

解决方案 »

  1.   

    填充到combobox这个总会吧,你自己
    select distinct  u_name   u_sex from table 就可以
      

  2.   

    select distinct uname, u_born from u_table
      

  3.   

    select distinct u_name,u_born  from table不过你给的数据没有发现重复的
      

  4.   

    to califord(远方) :感觉如果在combobox上不显示u_sex的话,在Combobox中就出现相同的u_nama和u_born,所以在select的时候不把u_sex带进去是对的.
    不过我没有测试我的sql...
      

  5.   

    假如你的表名字是 table1 
    可以这样:select u_name,u_born from table1 a
    where not exists
    (select count(*) from table1 b where a.u_name=b.u_name and a.u_born=b.u_born having count(*)>2  )
      

  6.   

    create table u_table
    {
     u_name nvrchar(20),
     u_sex  nvrchar(1),
     u_bron nvrchar(10),
     u_group char(10)
    }执行下面语句返回一个数据集,我用DataSet(怎么得到DataSet就不说了)
    select distinct u_name,u_born from u_table
    再填充combobox 如下: combobox .DataSource     =  DataSet
     combobox .DisplayMember  = "u_name"   
     comboBox.ValueMember     = "u_born";
      

  7.   

    你的表没有主键吗?
    建议把主键也一起取出来,赋给combobox的ValueMember.select [主键],u_name,u_born from [table]取出DataTable(DataSet)后,绑定combobox:
    combobox.DataSource = dt;//datatable
    combobox.ValueMember = [主键];
    combobox.DisplayMember = "u_name";
      

  8.   

    lovvver(www.notsoft.cn) 说到问题关键,这种表最好建主键!!
      

  9.   

    select distinct u_name,u_born from u_table
      

  10.   

    这个SQL语句大家对了,但我不知将它全用一个combobox能显示吗?
      

  11.   

    你用combobox显示这几列?建议用ListBox
      

  12.   

    select u_name form Mytable where not exits(select u_born from Mytable) lift join select u_born from Mytable
    我没调,也不知道你用的什么数据库和工具,你自己照着调一下吧。
      

  13.   

    对数据库数据的显示,天然的选择:DataGridView,其次ListView,或其他能显示多行的控件,一般不会用combobox,它是用来选择不同条件(情况),产生不同效果的东东。有如switch/case语句一样。
      

  14.   

    select names from bbb union select xname from bbb标准答案,简单明了.
      

  15.   

    select distinct uname, u_born from u_table
      

  16.   

    而且填充到的是两个combobox中,在combobox中显示的数据应该没有重复的就可以了!
      

  17.   

    select distinct u_name,u_born from u_table
      

  18.   

    select distinct u_name from u_table
    select distinct u_born from u_table
      

  19.   

    看了 lz 后面的回复,更加疑惑题目的表达是否正确?
    --------------
    但是我想在读取的时候,把重复的过滤掉而且一次我要读取u_name和u_born这两列
    而且填充到的是两个combobox中,在combobox中显示的数据应该没有重复的就可以了
    --------------
    这两个combobox 是否没有关联的?
    你是否只是要返回2个数据集?你是否只想用一次数据传输?
    如果是,可以尝试写存储过程,一次传输返回2个数据集。
      

  20.   

    写查询语句的时候加上distinct 关键字就行了
      

  21.   

    select distinct  u_name   u_sex from table 就可以
      

  22.   

    这么简单的问题.还跟了那么多人,第一个回复就ok:select distinct  u_name   u_sex from table
      

  23.   

    select distinct  u_name   u_sex from table这个不可以,会丢数据的,你们仔细看他的需求没有啊?
    用这个:
    select names from bbb union select xname from bbb