Search code examples
mysqlsqldatabasevarchar

How do I display only a portion of a VARCHAR in SQL


My query returns a list of email address of users from a database. However instead of displaying the full email address, I only want it to display the provider. eg hotmail.com gmail.com etc. What would I need to add? Edit: Im using MYSQL Workbench


Solution

  • Something like:

    substring(email from position('@' in email) + 1)
    

    As defined by ANSI/ISO SQL:

    <character position expression> ::=
    POSITION <left paren> <character value expression 1> IN <character value expression 2>
    [ USING <char length units> ] <right paren>
    

    Supported by Mimer SQL.