I need help as is this query now Promos appear first desired but Not sorted by price [price asc] although after promos further down the non promos are sorted… This i want is both SORTED but ALL promos appear first… I have to apply “group by” but how … to group by promos and not ? promos and main cars tables shown below…well?
$ttQuery = "SELECT
c.*, DATE_FORMAT(c.SYS_CREATION_DATE,'%d-%b-%y') AS creationDate, p.id as promoID
FROM
cars c
LEFT OUTER JOIN promo p
ON c.ID = p.ID
$searchCondition
ORDER BY
you do not want GROUP BY, that is not what GROUP BY is for
try this –
ORDER
BY CASE WHEN p.id IS NULL
THEN 'humpty'
ELSE 'dumpty' END
, c.id DESC
, price ASC
, c.SYS_CREATION_DATE DESC
, c.model ASC
note because it’s a LEFT OUTER JOIN, you want c.id in the ORDER BY, not p.id
I put p.id to get first promos… you mean only in thus new query you provided. …? in this case I think better c.id desc ignore it completely. … well? To Test soon…