'Find a string in one column if exist than give that value othere wise find in other column in a single mysql query

I have 3 column in database with 20000 records.

Let take a example

id | country_string       |  country_code<br>
275| Bangalore,BLR-India  |  BLR<br>
375| Basongo,BAN          |  BAN

I have given one record. I'm searching BLR. First it should match from country_code column if there then it will return the record otherwise it should search in country_string.It should be in single query.

if I'm using LIKE query And I search BAN It will give both record but It should come record number 375 and searching bang it should give record number 275



Solution 1:[1]

You can do this with LIKE.

Query

SELECT * FROM tableName
WHERE country_code LIKE '%BAN%'
OR country_string LIKE '%,BAN%';

Solution 2:[2]

select * from table where 
country_code like '%$search_name%' 
OR country_string like '%$search_name%'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2