hi have an category table
categoryId
Categoryname
Type
these are column name’s so i need to show all categories where type=’card’ but General category on top here is my code
SELECT * FROM `tbl_Catagory`
where CatagoryId=1 and type='Card'
union select * from tbl_Catagory`
where CatagoryId !=1 and type='Card'
order by CatagoryId desc`
here i get desc order but general on bottom so what i need is general category on top with the remaining categories displayed in descending order based on categoryId
You don’t need
UNION:This works because
Trueevaluates to1andFalseto0. The first part of theORDER BYmakes sure that only those withCatagoryId=1are ordered first. Then, all the rest which are subsequently ordered by their CategoryId in descending order.