© 2012 triAGENS GmbH | 2012-04-04 42 LET: variable creation SQL approach: SELECT u.*, GROUP_CONCAT(f.uid) AS friends FROM users u (INNER) JOIN friends f ON u.id = f.uid GROUP BY u.id HAVING COUNT(f.uid) > 5 Notes: we are using 2 different tables now the GROUP_CONCAT() aggregate function will create the friend list as a comma-separated string need to use GROUP BY to aggregate non-portable: GROUP_CONCAT is available in MySQL only