What you can do is build the SQL in a dynamic form using the following query:
SELECT GROUP_CONCAT(
DISTINCT CONCAT(
'(select jobid, projectid, desc from jobs where projectid=',
projectid,
' order by jobid limit 5)')
SEPARATOR ' union ') AS q
FROM table_1;
Save the result into a variable, and then execute the saved SQL.
David Rabinowitz
2009-07-26 14:46:53