Is it possible that select records for example 20 records from the table randomly, but in addition 1 certain record for example 3rd record.

Let me explain:

SELECT * from table limit 1, 20 rand();

In this way I will get 20 randomly records but I want that one certain record should must contain in these records, lets suppose id = 3 should also contain in these 20 records.

How can i retrieve this with a single query?

As far as I know its impossible, a query will always return a result set according to certain parameters passed. So all of your results must have something in common (or something they are commonly lacking).

If you really had to do it in one statement i would recommend using UNION, eg:

$sql = $sql1." UNION ".$sql2;

where $sql1 selects your "definite" records and $sql2 selects your random records.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.