MySQL – Extract All Links Table

myisamMySQLmysql-5.6

I have a table just like attached image. enter image description here

The query i am using to fetch the data is

SELECT  message_text 
FROM    messages 
WHERE   conversation_id = "69_P" 
AND     message_type = "text" 
AND     message_text LIKE "%http%" 
LIMIT 3

With this query i get the data with links as well as text. So is there any way to grep only links that start with http or www and ends with .domain or any?

Result Output

https://www.1and1.com/
Test  https://www.google.com
Test message with link  <a href="https://momentjs.com/docs/">https://momentjs.com/docs/</a>

Desired output

https://www.1and1.com/
https://www.google.com
https://momentjs.com/docs/

Best Answer

LIKE '%http%www%domain.com%'

will find the lines. But SQL cannot extract the desired part. Instead, do the extraction in your application code.

OR...

Redesign your schema to already have the URL in a separate column.