Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Intercept the field part before comma when querying SQL.
Intercept the field part before comma when querying SQL.
You can use the substring_index(column,',', 2) method.

The specific SQL statement is:

select id,name,substring_index(address,',',2 from people;

Substring_index(address,',', 2) means to truncate all characters before the second','.

Extended data

The related usage of substring () in sql is introduced;

1, SUBSTRING(name, 3) truncates all characters after the third character in the name field.

Select substring ('1234567', 3)

Results: 34567

2.SUBSTRING(name, -4) intercepts the fourth character position (reciprocal) of the name field and starts to fetch it until the end.

Select substring ('1234567', -4)

Results: 4567

3.SUBSTRING(name,-44,2) intercepts the fourth character position (reciprocal) of the name field, and only intercepts the last two characters.

Select substring ('1234567',-4,2).

Results: 45

4. Substring _ index ('www.baidu.com','.', 2) intercepts all characters before the second'.'.

SELECT substring _ index(' www . Baidu . com ','.', 2)