A. Crispino
A. Crispino

Reputation: 65

Encrypting MySQL, What does this query do?

So I was going through some work stuff and saw this. Can please somebody explain me what this does? The only thing I knew is that Active_Tournaments is View full of md5 Hash values.

select iT.TID
  from (
    SELECT @s := @s + 1 id, TID FROM Active_Tournaments, (SELECT @s := 0) AS s
    ) as iT
inner join
    (
        SELECT CEIL(RAND() *
            (SELECT MAX(id)
                    FROM (select *
                            from (SELECT @t := @t + 1 id
                                    FROM Active_Tournaments,
                                        (SELECT @t := 0) AS s) as iT) as ittt)) as id
    ) as ceil
    on iT.id = ceil.id;

Thanks in Advance

Upvotes: 0

Views: 36

Answers (1)

nbk
nbk

Reputation: 49395

it shows some randon TID from Active_Tournaments

SELECT @t := @t + 1 id
FROM Active_Tournaments,
   (SELECT @t := 0) AS s

This gives every row in Active_Tournaments a rownumber

Then you get the highest rownumber MAX(id) and multiplies it by a random number.

With CEIL you get again a Integer number.

In the first SELECT

 (
 SELECT @s := @s + 1 id, TID FROM Active_Tournaments, (SELECT @s := 0) AS s
 ) as iT

you again add a row number to the Active_Tournaments and select only the rows that has a corresponding number in CEIL(RAND() * MAX(id)).

So you get pseudo random TIDs

I would add

select DISTINCT iT.TID

Even if there are a big number of rows, random could produce the same number.

Upvotes: 1

Related Questions