I have table with username column, need filter this table where username start with…
- User
I have table with username column, need filter this table where username start with 'user_' and parse id after 'user_' in select MySQL
- Assistant
To filter a table where the
usernamecolumn starts with'user_'and then extract the ID that follows'user_', you can use theLIKEoperator in theWHEREclause along with theSUBSTRINGfunction or theSUBSTRING_INDEXfunction. Here's an example query that demonstrates how to do this:sqlSELECT username, SUBSTRING(username, 6) AS user_id -- Extracts the ID after 'user_' FROM your_table_name WHERE username LIKE 'user_%';Explanation:
-
LIKE 'user_%': This condition filters the rows where the starts with . The is a wildcard that matches any sequence of characters following .
-