I have this query that selects 10 related videos to the given video from `videos` table. I want `always to have 10 results` so if this query fails to get results or there are less than 10 results another query with less where conditions will be executed. I was counting the rows in `php` before, making another query and merging the results. It was so slow and the code got too long. I know it is better and faster to do in SQL. I'm using `PDO` with `php`.

How can I combine them?

First query (main one):

```
select * from videos
where FROM_UNIXTIME(published) BETWEEN
DATE_SUB(FROM_UNIXTIME(:published), INTERVAL 6 MONTH)
AND DATE_ADD(FROM_UNIXTIME(:published), INTERVAL 6 MONTH)
and video_name != :video_name
ORDER BY RAND() limit 10";

```

Second query(fallback):

```
select * from videos ORDER BY RAND() limit 10

```