select users.name
from(
select users.name, pay.uid,
RANK() OVER(ORDER BY count(pay.uid) DESC) AS ranking
from pay, users
where users.uid = pay.uid
group by users.uid)
where ranking = 1
i only want to get users.name output not name,uid,rank.
>Solution :
SELECT sub.name
FROM (SELECT users.name, pay.uid,
RANK() OVER(ORDER BY count(pay.uid) DESC) AS ranking
FROM pay
INNER JOIN users
on users.uid = pay.uid
GROUP BY users.uid) sub
WHERE ranking = 1
- alias the inline view (sub)
- change alias on outer select to sub instead of pay
- THe outer query has no knowledge of the tables inside thus the sub alias.
- avoid using , for joins that’s a 1980s technique the newer standars are to use joins (inner, outer, left right, cross etc.)