lundi 10 juin 2019

Mysql union 2 queries containing order by and random

I have a table with below columns: id (AI), status (boolean 0 or 1), created at (datetime)

I want to get records which has status = 1 and order them by created at DESC, another get random records which has status = 0

I run code as below but can not return correct answer.

(SELECT *
FROM
    `Teacher` AS `teacher`
WHERE
    `teacher`.`status` = 1 ORDER BY `created_at` desc)

UNION 

(SELECT *
FROM
    `bouhun`.`missions` AS `Mission`
WHERE 
   `teacher`.`status` = 0 ORDER By rand())




Aucun commentaire:

Enregistrer un commentaire