0

In my MySQL i want to look for characters in a specific ORDER...

the following code doesn't care how 'o' 'l' 'd' appear... so words containing those characters would be matched...

I'm only interested in doing the match if 'o' appears first, 'l' second and 'd' third.

Alternatives to REGEXP are also welcome!

SELECT DISTINCT(col) 
FROM tab 
WHERE col REGEXP 'o'
AND col REGEXP 'l'
AND col REGEXP 'd'
GROUP BY col
ORDER BY col DESC
1
  • DISTINCT isn't a function DISTINCT should be used as SELECT DISTINCT col Commented Nov 10, 2017 at 18:53

1 Answer 1

1

You should try the following

SELECT col 
FROM tab 
WHERE col like "%o%l%d%"
ORDER BY col DESC
Sign up to request clarification or add additional context in comments.

5 Comments

DISTINCT isn't a function DISTINCT should be used as SELECT DISTINCT col
You are right, good catch Raymond. I updated the query string.
Ricardo, yes the % are wildcards in the like statement.
Don't do both DISTINCT and GROUP BY. And do neither if col is not duplicated.
Good catch Rick James

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.