Mysql
 sql >> Database >  >> RDS >> Mysql

Come posso forzare una sottoquery a restituire solo una riga?

Puoi usare LEFT JOIN invece di Sub-Query .

Prova questo:

SELECT e.id, e.table_code,g.*
FROM events e
LEFT JOIN (SELECT MIN(date_time) date_time,
         SUM(score) score,
         type,
         post_id,
         table_code,
         comment_id,
         context
   FROM events 
   WHERE author_id = 32
   GROUP BY type, post_id, table_code, comment_id, context
   ORDER BY MIN(date_time) DESC
   LIMIT 15 ) g ON e.table_code = g.table_code AND e.date_time >= g.date_time
WHERE e.author_id = 32
ORDER BY seen ASC, e.date_time DESC