![]() Query 8 will pick those rows with characters within the range specified within the square bracket ‘’. Here, note that the characters should be mentioned ‘without’ comma operator inside the square brackets. So the four rows will be selected to display. We have mentioned characters ‘a, ‘b’, and ‘c’ within the square bracket. Query 7 picks rows with characters specified within the ‘’ under column E_Name. We can put this exact requirement in two ways, first by mentioning all three characters as an array and second by mentioning the range of characters from ‘a’ to ‘c’.Ĭode: select * from emp where E_Name REGEXP '' ![]() ![]() Here we can see how to search for a set of characters and a range of characters.įor example, let’s assume we need to identify the rows from the employee table with any of the characters’ a,’ b’, and ‘c’ in the E_Name column. So far, we have discussed searching for a single character, word, or a portion of a word. And as the output picked two entries from the table, which have character ‘a’ at the final character of the location, California and Alabama. The query specifies to select entries from the employee table for which the location field ends with the character ‘a’. Here we see how to search for an ending character/ word/ part of the word.Ĭode: select * from emp where Location REGEXP 'a$' Also, since the BINARY function is mentioned in the query, it will check for case sensitivity too. And from the sample table, we get two rows satisfying the condition, which are New York and New Jersey. The query says to select the entries for which the location field starts with the word ‘New’. Here we can search a part of a word as well.Ĭode: select * from emp where Location REGEXP BINARY '^New' Here we got the details of employees with the character ‘E’ in upper case at the beginning. Here let’s make it upper case and try to retrieve the output.Ĭode: select * from emp where E_Name REGEXP BINARY '^E' Since we specified the lowercase character ‘a’ in the query, no results could be retrieved. Here we make it more specific by making it case-sensitive.Ĭode: select * from emp where E_Name REGEXP BINARY '^a' So far, the characters or strings considered as the pattern were not case-sensitive. Here, we used the operator ‘^’ along with the pattern to be searched and thus got the details of employees whose name starts with the character ‘a’. Here we see how to select the details of an employee whose name starts with a specific character.Ĭode: select * from emp where E_Name REGEXP '^a' The specified character could be anywhere in the word. Here we just mentioned selecting data with a character. So we wrote the query for selecting details with a string in it. And as we look at the output, we can understand that out of 5 employees, 3 have the character ‘a in their names: Alan, Carl, and Dave. To analyze the query, we have described it to select all details from table ’emp’ with the character’ a’ in their E_Name field. Here we need to get the details of employees with the character ‘a’ in their names.Ĭode: select * from emp where E_Name REGEXP 'a'
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |