I have a Main-Datatable like this:
ID | Name | |
---|---|---|
1 | John Conner | [email protected] |
2 | Tyson, Mike | [email protected] |
3 | Harrison Ford | [email protected] |
The structure of the names are not the same.
My problem and question is, how do I get the name if I only enter the last name?
For example, I get the name "Tyson, Mike" when I type the name "Tyson". I don't get the name "John Conner" when I type the name Conner.
Is it possible to find the last name entered in the email address in order to display the name from Column "Name"?
The result of the following query shows me all names:
SELECT name FROM students WHERE email regexp '(?<=\.).*?(?=@)'
The result of the email.Regxp is the last names. How can I compare the regex result with the name "Conner"?
CodePudding user response:
Assuming that the last name would always be just a single word (not always true, e.g. Jean-Claude Van Damme
, we can try the following approach, e.g. for Tyson
:
SELECT *
FROM students
WHERE Name LIKE '% Tyson' OR Name LIKE 'Tyson,%';
The above logic caters to the last name either being the last word in the Name
field, or the first word in the Name
field, followed by a comma.
CodePudding user response:
You can use LIKE Operator for this.
SELECT name FROM students WHERE email LIKE '%email%'
hope this will help you.