mySQL: Subqueries Part 2

You can use subqueries as column expressions. The most common use of them as column expressions is probably as averages or counts, but you can use any expression that returns a row. Here I want to select only the rows that correspond to apps.


SELECT 
(SELECT app.name FROM app WHERE app.id = (log.product_id -100)) AS name,
 product_id, COUNT( * ) AS `count`
FROM  log
GROUP BY name

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.