sql如何选择一列中id不同的记录?

解决方案 »

  1.   

    select distinct(id) from ...
      

  2.   

    不就是去掉重复值就是拉
    select distinct ID from Table
      

  3.   

    SELECT TOP 6 et.name, quote.bid, quote.ask, et.PX, 
          quote.datetime
    FROM et INNER JOIN
          quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    ORDER BY quote.id DESC我的代码是这样的  现在要选择id不同的 应该怎么写?
      

  4.   

    用group by吧!不過不見得要是你上面這樣的話,不見得能找出唯一的6條id來
      

  5.   

    有没有唯一值字段.如果有可以用max来取
      

  6.   

    select distinct ID from Table
      

  7.   

    select top 6  et.name, quote.bid, quote.ask, et.PX, quote.datetime from FROM et INNER JOIN
          quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218) and et.id in(select distint(id) from et)
    ORDER BY quote.id DESC
      

  8.   

    SELECT TOP 6 et.name, quote.bid, quote.ask, et.PX, 
          quote.datetime
    FROM et INNER JOIN quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    group by et.name, quote.bid, quote.ask, et.PX, quote.datetime
    having count(1) = 1
    ORDER BY quote.id DESC
      

  9.   

    SELECT TOP 6 et.name, quote.bid, quote.ask, et.PX, 
          quote.datetime
    FROM et INNER JOIN quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    group by quote.id, et.name, quote.bid, quote.ask, et.PX, quote.datetime
    having count(1) = 1
    ORDER BY quote.id DESC
      

  10.   

    SELECT TOP 6 et.name, quote.bid, quote.ask, et.PX, 
          quote.datetime
    FROM et INNER JOIN quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    group by quote.id, et.name, quote.bid, quote.ask, et.PX, quote.datetime
    having count(1) = 1
    ORDER BY quote.id DESC
      

  11.   

    还是不对!
    et.id还是有重复!!!
      

  12.   

    其实很简单:selct * from table 
    where id in 
    (
    select  ID  from Table group by id having count(*) = 1
    )
      

  13.   

    quote表和et表都有一个id   et.id和quote.code关联
    et.id不是唯一的他们是有重复
    但是quote是唯一的
    现在我想选出et.id为72,73,215,216,217,218的记录
    (注意这些编号在et.id中是重复出现的)
    我想选出最新的并且编号为72,73,215,216,217,218的记录
      

  14.   

    Simba_Ji() 
    我的代码如何写才能答到那种效果?
      

  15.   

    你取 数据的时候 遇到 重复的 ID 你怎么区别取哪一条? 你要的SQL语句的关键就是取哪一条这个条件
      

  16.   

    select TOP 6 name, quote.bid, quote.ask, PX, quote.datetime
    from quote join 
    (
    SELECT et.id,et.name,et.PX
    FROM et INNER JOIN quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    group by et.id, et.name, et.PX
    having count(1) = 1
    ) as T
    ORDER BY quote.bid DESC
      

  17.   

    select TOP 6 name, quote.bid, quote.ask, PX, quote.datetime
    from quote join 
    (
    SELECT et.id,et.name,et.PX
    FROM et INNER JOIN quote ON et.id = quote.code
    WHERE (quote.code = 72) OR
          (quote.code = 73) OR
          (quote.code = 216) OR
          (quote.code = 215) OR
          (quote.code = 217) OR
          (quote.code = 218)
    group by et.id, et.name, et.PX
    having count(1) = 1
    ) as T
    on T.id = quote.code
    ORDER BY quote.bid DESC
      

  18.   

    select max(id),max(...),max(...) from 表 group by id