查询结果示例2:#id #title #content
435   t1     ''
422   t2     ''
390   t3     ''
389   t4     ''
345   t5     ''
320   t6     'c1'
237   t7     'c2'
123   t8     'c3'
103   t9     'c4'
100  t10    'c5'

解决方案 »

  1.   

    表:software
    字段:id(int), title(varchar(50)), content(text)...根据Web页面设计要求,页面中需要显示10条记录,前五条不需要content信息,后五条需要content信息。为了减少页面的流量,想把查询设计成上文要求的形式。对于前五条记录,只简单的返回一个空字符串。请教用最少的查询语句实现的方法。
      

  2.   

    select id,title,'' as content from software where rowid<=5
    union
    select id,title, content from software ;
      

  3.   

    呵呵,还是没说明白
    前五条不需要content信息
    >>>>>>>>>>>
     是不需要数据库中记录上的 CONTENT  信息,
     还是
     不要在数据库中 CONTENT 字段上有信息的记录 ????
    SELECT id, title, '' AS content  FROM software  LIMIT 5
    UNION
    SELECT id, title, content FROM software WHERE  LIMIT 4,5
    SELECT id, title, content FROM software WHERE content = "" LIMIT 5
    UNION
    SELECT id, title, content FROM software WHERE content <> "" LIMIT 5
      

  4.   

    我想诸位一定误会我的意思了:1、每个content字段里面都是有内容的,但是在查询结果中,前5个需要其内容,后5个不需要其内容(保持为空);2、hosia(红霞飞) 您的查询语句中的rowid是什么字段?
      

  5.   

    那个根据什么条件来确定哪些记录作为前5条???
     
    并且其content为空?那些是后5条???content又要有呢?
      

  6.   

    SELECT id, title, '' AS content  FROM software  LIMIT 5
    UNION
    SELECT id, title, content FROM software LIMIT 4,5