Hello Listpeople,

I need to output headline and link information from an 'articles' table.
Each article belongs to one and only one 'section'. I will probably need a
different number of articles from each section. I'm wondering about
performance, in very general terms, of a few different strategies outlined
below.


I imagined using a single SELECT like:
1.) SELECT * FROM articles WHERE section IN ('music','art','books'...) LIMIT
??
but couldn't figure out how to get 4 records from 'music' and 6 records from
'art'.


I imagined using 6 different queries, then patching the results together in
my application:
2.)
  a.) SELECT * FROM articles WHERE section='music' LIMIT 4
  b.) SELECT * FROM articles WHERE section='art' LIMIT 6
        etc.
but thought this might be a lot of queries to throw at the database for each
page request.


Then I thought that I could send in one big old query using a UNION:
3.)
  SELECT * FROM articles WHERE section='music' LIMIT 4
  UNION
  SELECT * FROM articles WHERE section='art' LIMIT 6
  UNION
  SELECT * FROM articles WHERE section='books' LIMIT 6
  etc.

Could anyone comment on these 3 strategies and any 'gotchas', limitations,
other considerations that I haven't, uhh, considered?

--
Wellington





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to