How to get available seat codes?

This is a rather complicated MySQL query for me.

I have a table of phone numbers in the format of an American phone number 8153216458.

Example:

TABLE: numbers(number)
4512163215
4512158211
4512110579
8812163215
9405462136
3021548641

I want a list of available area codes (how I sell numbers) without repeating them. Some queries that are based on the first three digits and finally are ordered correctly.

Output:
302
451
881
940

Any solution? I don't mind if he still uses php manipulation.

thank

+3
source share
2 answers

Try the following:

select distinct substring(number, 1, 3)
  from numbers;

Or, as Jeff mentioned in the comments, is leftalso an option:

select distinct left(number, 3)
  from numbers;

Check out the documentation for string functions in MySQL.

+5
source

- ?

(, 0, 3) ""

+2

Source: https://habr.com/ru/post/1775701/


All Articles