Sử dụng SUBSTRING_INDEX() lồng nhau (nested) để trích xuất chuỗi nằm giữa hai delimiter trùng nhau.
Ví dụ: Lấy 'tutorialspoint' từ 'www.tutorialspoint.com'
mysql> SELECT SUBSTRING_INDEX(
SUBSTRING_INDEX('www.tutorialspoint.com', '.', 2),
'.', -1
) AS 'Nested SUBSTRING_INDEX';
+------------------------+
| Nested SUBSTRING_INDEX |
+------------------------+
| tutorialspoint |
+------------------------+
Giải thích logic
SUBSTRING_INDEX(..., '.', 2)→ lấy từ đầu đến delimiter thứ 2:'www.tutorialspoint'SUBSTRING_INDEX(..., '.', -1)→ lấy phần sau delimiter cuối:'tutorialspoint'
Áp dụng chung: Để lấy phần giữa delimiter thứ n và n+1: SUBSTRING_INDEX(SUBSTRING_INDEX(str, delim, n+1), delim, -1)