AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Mysql like vs substring9/12/2023 ![]() Mysql update column with value from another table.SELECT INSTR(emp_lastName, 'ill') FROM employee_name_details Let us say we just want to retrieve the first occurrence of the substring ‘ill’ present in any of the values of column emp_lastName. Since we are doing SELECT * along with instr() function, the query returns the rows with the ‘ill’contained in the emp_lastName. Here, the instr() function returns the first occurrence of the substring ‘ill’ present in any of the values of column emp_lastName. SELECT * FROM employee_name_details WHERE INSTR(emp_lastName, 'ill') > 0 Observe the below solution demanded by the above example. NOTE: Order of arguments get reversed in the INSTR() function compared to LOCATE() function. Here str is the string passed in as the first argument, and substr is the substring passed in as the second argument. INSTR(str, substr) function returns the index of the first occurrence of the substring passed in as parameters. We will be using the INSTR() function for the solution. SELECT LOCATE('ill', emp_lastName) FROM employee_name_details Īs shown in the output, only two rows return the index of substring ‘ill’ present in the emp_lastName column. Let us say we want to retrieve the first occurrence of the substring ‘ill’ present in any of the values of column emp_lastName. Since we are doing SELECT * along with locate() function, the query returns the rows with the ‘ill’ contained in the emp_lastName. Here, the locate() function returns the first occurrence of the substring ‘ill’ present in any of the values of column emp_lastName. ![]() ![]() SELECT * FROM employee_name_details WHERE LOCATE('ill', emp_lastName) > 0 Observe the below query for the solution demanded by the above example. ![]() Here substr is the substring passed in as the first argument, and str is the string passed in as the second argument. LOCATE(substr, str) function returns the first occurrence of the substring passed in as parameters. We will be using the LOCATE() function for the solution. Looking for Something Search for: Search Recent PostsĮxample: Get all the rows from the table employee_name_details where the employee’s last name contains ‘ill’ ![]()
0 Comments
Read More
Leave a Reply. |