i have a question about RANKING records. First, a bit of setup:
Given table: tbl_List_No_Repeats (see below left), I can add a RANK column (see below right) by ...
...using either query qA or query qB (see below)
*** For very large tables, qA is SLOW, but qB is quite FAST.
Now to my question. I want to add a RANK column to a table that has REPEATED values, and I need it to be FAST, so I'm hoping to see code that is like qB above (using an INNER JOIN in a TOTALS query).
Consider table: tbl_List_with_Repeats (see below left), I can use the SLOW qA to add a RANK column (see below right) by changing only the source table name. But, is there a fast way to base the code on an INNER JOIN in a TOTALS query (like qB) when the table has repeated values?
thank you in advance for any help
Given table: tbl_List_No_Repeats (see below left), I can add a RANK column (see below right) by ...
Code:
[b][u]Val[/u] [u]Rank Val[/u][/b]
2 1 2
4 2 4
5 3 5
9 4 9
10 5 10
...using either query qA or query qB (see below)
Code:
qA (qA uses a SUBQUERY in the SELECT statement) qB (uses a INNER JOIN in a TOTALS query)
== ==
SELECT SELECT
(SELECT COUNT(*) AS Rank, x.Val
COUNT(*) FROM
FROM tbl_List_No_Repeats AS x
tbl_List_No_Repeats y INNER JOIN
WHERE tbl_List_No_Repeats AS y
x.Val + 1 > y.Val ON
) AS Rank, x.Val >= y.Val
x.Val GROUP BY
FROM x.Val
tbl_List_No_Repeats x ORDER BY
ORDER BY 2;
2;
*** For very large tables, qA is SLOW, but qB is quite FAST.
Now to my question. I want to add a RANK column to a table that has REPEATED values, and I need it to be FAST, so I'm hoping to see code that is like qB above (using an INNER JOIN in a TOTALS query).
Consider table: tbl_List_with_Repeats (see below left), I can use the SLOW qA to add a RANK column (see below right) by changing only the source table name. But, is there a fast way to base the code on an INNER JOIN in a TOTALS query (like qB) when the table has repeated values?
Code:
[b][u]Val[/u] [u]Rank Val[/u][/b]
2 1 2
4 2 4
4 2 4
9 4 9
10 5 10
10 5 10
10 5 10
22 8 22
thank you in advance for any help