This is a slightly more complicated version of what I posted earlier. I do not want to edit the original in order to ruin the excellent answer to the question I had at that time.
Suppose a table named tau.
tau:
A | B | C
----------
2 - 1 - red
3 - 1 - rod
4 - 1 - rope
6 - 5 - red
7 - 5 - rap
8 - 5 - rod
9 - 10 -rod
11- 10 -road
12- 13 -rud
Column A is the primary key. It will be unique. Column B is a foreign key. In my database, no integer key ever changes in tables. Column C is not a key.
This table will have many rows. There are many other columns, such as, for example, column C, which are indexed for search.
I want exactly M different values from column B. Let's say M = 2
, B ( !), , B.
select distinct B From tau Where C like 'r_d' AND B < 13 Order By B Desc Limit 2
B
10
5
. :
BC (C like "r_d" AND B < 13), A, B, , 2 B.
, where, true C.
, , .
A | B
------
9 - 10
8 - 5
6 - 5
, , M, 2 . , , M B. Postgresql?