Skip to content Skip to sidebar Skip to footer

Select Distinct Only First Four Numbers

Consider the following table: ticker code -------------- AA 151040 AAP 452020 DOW 151010 DVN 151020 EXC 452050 FAD 452070 POE 207010 I would like to

Solution 1:

Use LEFT:

SELECT LEFT(code, 4) AS code, ticker FROM tbl ORDER BY code;

Solution 2:

SELECTSUBSTRING(code,1,5) AS SUB_CODE,ticker
FROMTABLE;

Solution 3:

You can use Left function in mySql to select the first four Left(code,4) Then use order by.

Post a Comment for "Select Distinct Only First Four Numbers"