select * from table order by case when web_id= ‘4’ then 1 when web_id=’3′ then 2 when web_id=’6′ then 3 when web_id=’7′ then 4 when web_id=’2′ then 5 end, web_id
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
Consider the employee table with the fields emp_id and salary.
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
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
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