0

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?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Menster
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.