I have this db http://sqlfiddle.com/#!18/24f134/4/0 of which extracts the longest word with points that contained within the word with no points. I need to have the column (4th) of the word without points matching per row (that contains the word)
If I understand correctly, you want the matching phrase (without points) for each row that has points. APPLY
is useful in this situation:
SELECT w.id, w.phrase, w.points, w2.phrase
FROM words w OUTER APPLY
(SELECT TOP (1) w2.*
FROM words w2
WHERE w2.phrase LIKE concat('%', w.phrase, '%') and w2.points = 0
ORDER BY len(w2.phrase) DESC
) w2
WHERE w.points > 0;
Here is a db<>fiddle.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.