#### Topic: Randomnaja record with the given chance from other table

There are 2 tables storing the following data:
[spoiler] case_in:
[img=https://i.imgur.com/YGiTiiy.png]
items:
[img=https://i.imgur.com/ceioIF4.png]
[/spoiler]
The task: to receive single line from the given list of subjects , increased by certain chance.
Tried to make it so (1 request):

``SELECT * FROM ` items `, ` case_in ` WHERE items.id IN (2,3,4) ORDER BY RAND () *case_in.chance DESC LIMIT 1``

But I understand that chances case_in.chance do not coincide in any way with the necessary lines.
Earlier the table was one, chances have been correlated to each subject the. The request was such (2 request):

``SELECT * FROM ` items ` WHERE ` id ` IN (2,3,4) ORDER BY RAND () * ` chance ` DESC LIMIT 1``

But such variant does not correspond to current requirements, therefore has been removed.
As a whole, the task dares sampling of lines from ` items `,  to them corresponding ` chance ` on ` item_id `, and then operation of similarly second request, but I not especially understand, how it correctly to write.
How to receive similar result from the second request, but by means of these two tables?

#### Re: Randomnaja record with the given chance from other table

What sense of field values chance? Records to give with probability 1:99:100 or 1:98:1?

#### Re: Randomnaja record with the given chance from other table

Erriour wrote:

to them corresponding ` chance ` on ` item_id `

Well and where it in request?
How tables should be connected among themselves?

#### Re: Randomnaja record with the given chance from other table

Akina, from 1 to 100. A Prime number not dependent on any certain number. The above number, the above chance that falls out.
miksoft so I also do not know how it to write down...

#### Re: Randomnaja record with the given chance from other table

Erriour;
Well and do - through :

``````SELECT *
FROM ` items ` i
JOIN ` case_in ` c
I. ID = c. ITEM_ID
WHERE i.id IN (2,3,4)
ORDER BY RAND () *c.chance DESC
LIMIT 1``````

#### Re: Randomnaja record with the given chance from other table

Erriour;
But as a whole, the approach - incorrect....

#### Re: Randomnaja record with the given chance from other table

Kind  - Eh, yes that is necessary. Thanks