I have 3 tables: video, video\_category and video\_category\_join.

One video can have multiple video\_category and a video\_category can be associated with multiple videos: therefore the video\_category\_join table

**TABLE: video** 

```
| video_id | title | description | duration |
|--------------------------------------------
| 12       | hello | ...         | 190      |
| 24       | hello | ...         | 190      |
| 78       | hello | ...         | 190      |
| 34       | hello | ...         | 190      |
| 91       | hello | ...         | 190      |
| 88       | hello | ...         | 190      |

```

**TABLE: video\_category** 

```
| video_category_id | name    |
|------------------------------
| 4                 | music   |
| 8                 | tv      |
| 5                 | black   |
| 2                 | politic |
| 1                 | movie   |
| 6                 | other   |

```

**TABLE: video\_category\_join** 

```
| video_id | video_category_id |
|------------------------------
| 24       | 4                 |
| 24       | 5                 |
| 88       | 1                 |
| 91       | 6                 |
| 91       | 5                 |
| 78       | 4                 |

```

Given a `video_id`, i want to pick random videos that DON'T have the same category as the given `video_id`.

So, for example, if the `video_id` is 24, the result set should return videos that dont have the same category as `video_id` 24. In this case, the only videos that dont have the same category as `video_id` 24 are: `video_id` 88.

This is a query that i thought could work, but if the given `video_id` has no categories it returns nothing.

```
SELECT DISTINCT v.video_id, v.title, v.duration, 2 AS preferred
FROM video_category_join vc
JOIN video_category_join vc2 ON vc2.video_category_id <> vc.video_category_id AND vc2.video_id <> vc.video_id
JOIN video v ON v.video_id = vc2.video_id
WHERE vc.video_id = 5
ORDER BY RAND()
LIMIT 20

```