A
A
Alexey2018-08-10 14:16:46
PostgreSQL
Alexey, 2018-08-10 14:16:46

How to select random records (N pieces) from the PostgreSQL database, but so that the list does not change during the subsequent selection under the same condition?

There is a table with records. Records in the same table have child records, they are located by the PARENT_ID of the parent.
Here it is necessary to choose "random child records" in the amount of let's say 10 pieces (always less than the total number of child records). entries do not have to be in order. Required in random order.
But constantly, the next time this query is called, it is necessary that the list of records does not change.
Is there any solution using ONLY SQL?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
R
res2001, 2018-08-10
@res2001

Calculate the total number of records (N) that can be selected.
You generate 10 random numbers in the range from 1 to N.
You select 10 records from the top query whose row_id is equal to random numbers.
The IDs of the selected records need to be saved somewhere so that they can be used next time.

S
Sergey, 2015-01-22
@evil0o

Evy Nemeth - Unix and Linux. System Administrator
Guide nnm-club.me/forum/viewtopic.php?t=318876
rutracker.org/forum/viewtopic.php?t=4709004

V
Vladimir, 2015-01-22
@MechanID

I recommend getting some kind of test machine with gentoo installing the OS and solving various problems during use will give a lot of useful experience, in no case do not use it in production at first.

I
index0h, 2015-01-22
@index0h

Well, if you are used to rpm - install Fedora on a virtual machine, for example, on virtualbox, play with it, if everything is ok - install it as a second OS. Some time will pass and Windows will remain only for games))

S
Salavat Sharapov, 2015-01-22
@desperadik

Clarify the question for yourself: What exactly do you want to use Linux for in the future? Maybe like workstation, http-server, file-server, hVM? Or all together?

R
Ruben Harutyunov, 2015-01-23
@K_DOT

Course from the Linux Foundation

H
hermit, 2015-01-23
@Alex9

To the book from the first post Evi Nemeth - Unix and Linux. The system administrator
's guide is also this
one www.ozon.ru/context/detail/id/3178480

A
Alexey Pyanov, 2015-01-29
@gohdan

Once you're setting it up yourself, most beginner's guides won't be of any use. Try linuxfromscratch.org , a step-by-step guide to building a working GNU/Linux system from source. It gives invaluable experience of studying the insides of the system, you won’t be able to get so deep into windows;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question