Seems like you require to introduce the concept of relevance.
Try:
select * from (
SELECT 1 as relevance, * FROM wallpapers
WHERE tags LIKE '%New York%' OR name LIKE '%New York%'
union
select 10 as relevance, * FROM wallpapers
WHERE (tags LIKE '%New%' OR name LIKE '%new%')
and (tags LIKE '%York%' OR name LIKE '%York%')
union
select 100 as relevance, * FROM wallpapers
WHERE tags LIKE '%New%' OR name LIKE '%new%'
union
select 100 as relevance, * FROM wallpapers
WHERE tags LIKE '%York%' OR name LIKE '%York%'
)
order by relevance asc
By the way, this will perform very, very poorly if your database grows too large - you need to be formatting your columns consistently so they're all upper case (or all lower case), and you need to be avoiding wildcards in your where clauses if you probably can.
When you face this problem, you can look at the full text searching.
Want to be a SQL expert? Come and join this SQL Certification by Intellipaat.
Do check out the video below