Your suggestion works when I run the query. My problem now is that I need to save the query as a view in MySQL, and the SELECT statement cannot contain a subquery in the FROM clause in a MySQL view. I need it as a view because I must filter the result even more by using URL parameters on my webpages.