mercredi 30 août 2017

Mysql select with if else and order by statement

Without any training (and deaf) I developed a town portal system but I gave up on a specific select statement.

ORDER BY FIND_IN_SET(`townfield`,'TownA'), date LIMIT 3

ID1 TownB 2017-08-30 ID2 TownA 2017-08-22 ID3 TownA 2017-08-22 ID4 TownA 2017-08-22 ID5 TownC 2017-08-22 ID6 TownB 2017-08-10

The goal is that Town A select ID 2, 3 and 4, Town B select ID 1, 6 and 2 and Town C select ID 5, 1 and 2

In other words the town select his OWN articles first in date order with limit 3, ELSE select the remaining of the limit 3 in date order.

Aucun commentaire:

Enregistrer un commentaire