How to order PGSQL output depending on where clause

I want my output to be ordered as I filtered with where clause. I tried ORDER BY filename but it gives loc1-2main%','loc1-2branch%', 'loc2-3main%', 'loc3-4main%'. which is not what I wanted

select distinct fi.description as "Status", fi.filename,MAX(fi.createddate) AS "latestentry"
          from fileimport fi
          
          AND fi.filename LIKE ANY(ARRAY[['loc1-2main%', 'loc2-3main%', 'loc3-4main%', 'loc1-2branch%']])
          
          GROUP BY fi.filename, c2.description

Solution 1:

Place the where clause in the order clause

select distinct fi.description as "Status", fi.filename,MAX(fi.createddate) AS "latestentry"
from fileimport fi
          
where fi.filename LIKE ANY(ARRAY[['loc1-2main%', 'loc2-3main%', 'loc3-4main%', 'loc1-2branch%']])
     
group by fi.filename, c2.description
order by fi.filename LIKE ANY(ARRAY[['loc1-2main%', 'loc2-3main%', 'loc3-4main%', 'loc1-2branch%']])