View Single Post
Old 11-25-2012, 10:59 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,542
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
temp_table? t.f? Where did those come from, Bubikol???

And if there are only 4 records in temp_table, that will *NOT* get more than 4 records.

One simple answer:
Code:
SELECT X.* FROM 
  ( SELECT 1 AS dummy, * FROM table
    UNION
    SELECT 2 AS dummy, * FROM table
  ) AS X
WHERE X.jobcategory LIKE '%Admin%'
ORDER BY RAND() LIMIT 5
But it's not terribly efficient.

I would be strongly tempted to do this in PHP/JSP/ASP code, instead.

Read the 4 records into an array and then just pick a random array element 5 times.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote