Performing SQL string manipulations on a single column
use SUBSTRING_INDEX


CREATE TABLE Table1
    (`IP_address` varchar(15))
;
    
INSERT INTO Table1
    (`IP_address`)
VALUES
    ('1.2.3.4.5'),
    ('11.22.33.44.55'),
    ('5.6.7.8.9'),
    ('111.222.333.444')
;




SELECT SUBSTRING_INDEX(`IP_address`,'.',3) FROM Table1;


| SUBSTRING_INDEX(`IP_address`,'.',3) |
| :---------------------------------- |
| 1.2.3                               |
| 11.22.33                            |
| 5.6.7                               |
| 111.222.333                         |


db&lt;&gt;fiddle here