select all rows with a minimum value
As you have seen, a simple GROUP BY will not work because it would return only one record per group.
Your join works fine.
For a large table, it will be efficient only if there is an index on the join columns (num
and text
).
Alternatively, you could use a correlated subquery:
SELECT *
FROM t
WHERE num = (SELECT MIN(num)
FROM t AS t2
WHERE t2.text = t.text);
SQLFiddle
When being executed, this query does not require a temporary table (your query does for the result of u
), but will execute the subquery for each record in t
, so text
should be indexed. (Or use an index on both text
and num
to get a covering index.)