为什么我用了order by,在最后select出来的结果中,相同的记录会出现两次。代码是这样的。
SELECT *, tid AS Expr1, title AS Expr2
FROM dnt_topics
WHERE (fid = 19)
ORDER BY tid
这个表是discuz!nt的,我怀疑他是不是加了什么措施才会这样。

解决方案 »

  1.   

    SELECT distinct *, tid AS Expr1, title AS Expr2 
    FROM dnt_topics 
    WHERE (fid = 19) 
    ORDER BY tid 
      

  2.   

    order by 没有屏蔽相同记录的功能
      

  3.   

    SELECT distinct *, tid AS Expr1, title AS Expr2 
    FROM dnt_topics 
    WHERE (fid = 19) 
    ORDER BY tid 
      

  4.   


    order by 只是排序而已,可以通过distinct来过滤重复的记录
      

  5.   


    SELECT distinct *, tid AS Expr1, title AS Expr2 
    FROM dnt_topics 
    WHERE (fid = 19) 
    ORDER BY tid 
      

  6.   

    Order by 只是用来排序的。
    你要是想筛选数据,就该使用SELECT distinct *, tid AS Expr1, title AS Expr2 
    FROM dnt_topics 
    WHERE (fid = 19) 
    ORDER BY tid 
      

  7.   

    这个语句本身就是有问题的!SELECT *, tid AS Expr1, title AS Expr2 FROM dnt_topics WHERE (fid = 19) ORDER BY tid 在此举中你既然已经查询了所有的(*)为什么后边还要跟那几个转换列名的语句呢?要么你就一句一句的查,要用*查你就别指定列名!还有ORDER BY tid和tid AS Expr1本身就是相互冲突的,你已经将tid转换为Expr1了那么后边ORDER BY 有按什么去排序?