I want to generate 12 random questions from database which consist 4 easy, 4 medium and 4 hard questions. Also the questions must not repeated

This is my code:

```
SELECT * FROM chapter1
WHERE question_id NOT IN (SELECT question_id FROM 
                          chapter1_useranswer WHERE username = '$usernow') 
  AND (difficulty = 'easy')
LIMIT 4
UNION ALL
SELECT * FROM chapter1
WHERE question_id NOT IN (SELECT question_id FROM 
                          chapter1_useranswer WHERE username = '$usernow') 
AND (difficulty = 'medium')
LIMIT 4
UNION ALL
SELECT * FROM chapter1
WHERE question_id NOT IN (SELECT question_id FROM 
                          chapter1_useranswer WHERE username = '$usernow') 
AND (difficulty = 'hard')
LIMIT 4
ORDER BY RAND()

```

This code still got error.