查询结果示例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'
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'
字段:id(int), title(varchar(50)), content(text)...根据Web页面设计要求,页面中需要显示10条记录,前五条不需要content信息,后五条需要content信息。为了减少页面的流量,想把查询设计成上文要求的形式。对于前五条记录,只简单的返回一个空字符串。请教用最少的查询语句实现的方法。
union
select id,title, content from software ;
前五条不需要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
并且其content为空?那些是后5条???content又要有呢?
UNION
SELECT id, title, content FROM software LIMIT 4,5