I have a table named sentEmails
where the body
column contains the body text of an email.
In the body text, there is a substring like:
some link: <a href="https://somelink@somesite.com/somePage.php?someVar=someVal&sentby=agent">Random link text
Using MySql, I need to extract the url from this column like https://somelink@somesite.com/somePage.php?someVar=someVal&sentby=agent
I was thinking something like the below would work by finding the starting location and returning the next 150 chars, of course it actually just returns the first 150 chars.
SELECT LEFT(body, LOCATE('some link: <a href="', body)+150) AS link
FROM sentEmails
WHERE sent between date_sub(now(),INTERVAL 1 WEEK) and now()
AND body like '%some link:%'
AND toEmail = 'email@gmail.com'
Additional info:
- the link will always be preceded by the text
some link:
Random link text
at the end will change- I can live with getting a bit more of the text than need if I have to, for example, getting
https://somelink@somesite.com/somePage.php">Random link text
would be acceptable - the text shown above is a substring of the full
body
column which contains much more text - This isnt something Im going to be doing often. Im researching an issue and I need the links from 40-50 of these rows, Im just hoping to avoid having to pull the link manually from each row.
- I can only use MySQL Query Browser to access this DB if I could connect with php, this would be trivial
- The url in question, can have 6-25 parameters in it
- The url in question will always end with this parameter
&sentby=agent