I want to fetch all the records using a SQL query with the string 'John' in it. Condition is, John should appear after at least one hyphen (-)
Examples:
- Anna - Pam - John (Yes)
- John - Anna - Pam (No)
- Anna - John (Yes)
- John (No)
- Anna - Pam - Mike - PhilJohn (Yes)
- John - John (Yes)
Bad query example: Select * from users where name LIKE '%John%';
CodePudding user response:
You can use '%' in between - and John to allow any numbers of characters in between.
your query will be like this
Select * from users where name LIKE '%-%John%';