how to select characters after first 20 characters from field mysql

back123
 select address (first 20 character) as Address1 , 
        address (characters after first 20 if less then 20 then NULL) as Address2
 from customer

How do I select string after 20 characters?

Gohn67

To get characters after the first 20 characters (note that if there are not twenty characters, the function will return an empty string):

SELECT SUBSTRING('Some Random Address That is Longer than 20 characters' FROM 20);

Now if you need address 2 to be NULL, you check character length first:

SELECT if(char_length(address) > 20, SUBSTRING(address FROM 20), NULL);

To get the first 20 characters, you can use the substring function like this:

SELECT SUBSTRING('Some Random Address', 1, 20);

Now the final query could look like this:

SELECT SUBSTRING(address, 1, 20) as Address1, 
    IF(CHAR_LENGTH(address) > 20, SUBSTRING(address FROM 20), NULL) as Address2
FROM customer

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use Curl to also output first 20 characters from the response?

From Dev

MySQL select 3 first characters and replace

From Dev

Select the first 90 characters from the content

From Dev

How to delete characters after a "." (dot) in the first column?

From Dev

How to delete characters after a "." (dot) in the first column?

From Dev

How to Add characters after the first instance of a character

From Dev

php echo only first 20 characters from a variable string

From Dev

how to select n first characters from first column according to the number of the second column

From Dev

Select MySQL with max characters

From Dev

How to sort digits after certain characters (-) in mysql

From Dev

MySQL - is it safe to check the 6 first characters of a query to be sure it is a SELECT?

From Dev

MySQL - is it safe to check the 6 first characters of a query to be sure it is a SELECT?

From Dev

How to get strings first 4 characters after first semicolon

From Dev

how to select a some characters from string in javascript

From Dev

Select only n number of characters from VARCHAR(MAX) field

From Dev

AngularJS select - match first characters

From Dev

How do i after first 110 characters from database text, create link

From Dev

MySQL - Replacing first space with characters

From Dev

MySQL - Replacing first space with characters

From Dev

Garbled characters from MySQL

From Dev

how to count characters before/after the first space in line?

From Dev

How to replace first instance of x after y amount of characters in Excel?

From Dev

How can I remove all characters after the first instance of a tab?

From Dev

How to add an ellipsis hyperlink after the first space beyond 170 characters?

From Dev

To grep 20 characters after and before match

From Dev

How to find rows with only special characters on a field using MySQL?

From Dev

Remove first two quotes from lines more than 20 characters long

From Dev

Replace first few characters of field in an update statement

From Dev

How to limit the amount of characters returned from a field in a Mongo query

Related Related

  1. 1

    How to use Curl to also output first 20 characters from the response?

  2. 2

    MySQL select 3 first characters and replace

  3. 3

    Select the first 90 characters from the content

  4. 4

    How to delete characters after a "." (dot) in the first column?

  5. 5

    How to delete characters after a "." (dot) in the first column?

  6. 6

    How to Add characters after the first instance of a character

  7. 7

    php echo only first 20 characters from a variable string

  8. 8

    how to select n first characters from first column according to the number of the second column

  9. 9

    Select MySQL with max characters

  10. 10

    How to sort digits after certain characters (-) in mysql

  11. 11

    MySQL - is it safe to check the 6 first characters of a query to be sure it is a SELECT?

  12. 12

    MySQL - is it safe to check the 6 first characters of a query to be sure it is a SELECT?

  13. 13

    How to get strings first 4 characters after first semicolon

  14. 14

    how to select a some characters from string in javascript

  15. 15

    Select only n number of characters from VARCHAR(MAX) field

  16. 16

    AngularJS select - match first characters

  17. 17

    How do i after first 110 characters from database text, create link

  18. 18

    MySQL - Replacing first space with characters

  19. 19

    MySQL - Replacing first space with characters

  20. 20

    Garbled characters from MySQL

  21. 21

    how to count characters before/after the first space in line?

  22. 22

    How to replace first instance of x after y amount of characters in Excel?

  23. 23

    How can I remove all characters after the first instance of a tab?

  24. 24

    How to add an ellipsis hyperlink after the first space beyond 170 characters?

  25. 25

    To grep 20 characters after and before match

  26. 26

    How to find rows with only special characters on a field using MySQL?

  27. 27

    Remove first two quotes from lines more than 20 characters long

  28. 28

    Replace first few characters of field in an update statement

  29. 29

    How to limit the amount of characters returned from a field in a Mongo query

HotTag

Archive