Reputation: 43
i need to know how substring_index
can only return all rows that match exactly the number of delimiters. In this case the .
For example this query:
SELECT
SUBSTRING_INDEX(ABC, '.', 4)
FROM xxx
only should output when the row is exactly something like this (with 4 words):
aaa.bbb.ccc.ddd
The problem is that: this row is also showed .
aaa.bbb
Upvotes: 4
Views: 998
Reputation: 15261
This will return anything where ABC has 3 .
delimiters.
select *
from xxx
where char_length(replace(ABC, '.', '')) + 3 = char_length(ABC)
You would need to multiply 3 by your delimiter length if you had a multi-character string for your delimiter.
Upvotes: 6