Retrieve Comma separated Values in a Table column by Mysql Query

FIND_IN_SET is the function which return result in searching for specific values in a comma separated values in a table column ,

You don’t need to use large set of record and array to filter those records  , use the query below to get records which you needed,


SELECT * FROM Table_name WHERE FIND_IN_SET(‘value’, column_name)


Have a look on the table columns i have web_class_id in a commas separated values , i want to retrieve web_class_id with value 63 now i will use the query below

SELECT * FROM Table_name WHERE FIND_IN_SET(’63’, web_class_id)

I got the result below



Mysql query to get 2nd highest salary

Consider the employee table with the fields emp_id and salary.

emp_id salary
1 10000
2 30000
3 15000
4 50000
5 25000

Now if you want get the 1st highest salary then you can use the below query

SELECT DISTINCT `salary` FROM `employee`ORDER BY `salary` DESC LIMIT 0, 1

RESULT: 50000

To find the 2nd highest salary then you can use the following query

SELECT DISTINCT `salary` FROM `employee`ORDER BY `salary` DESC LIMIT 1, 1

RESULT: 30000

Likewise you can find the any of the highest salary using the above query by changing the LIMIT value

Also you can find the highest salary in many other ways but this one of the easy way to find the highest salary.

Note: This is the most common question asked in many of the interviews