Jump to content

Select first 2 letters from SQL table


nashsaint

Recommended Posts

Hi,

 

Here's my SQL Table named 'Disks'

 

disk_id

model_no

job_no

 

'model_no' contains characters like HTSxxxxx, STxxxxx, 2Fxxxxx...etc..  What I want to do is to select model_no and truncate it in PHP so that i will only get the first 2 or 3 characters from the SQL query.  And then group the result into separate categories (i.e., HTSxxxxxx to Hitachi category, STxxxx to Seagate Category... etc.). 

 

Is there anyone who can guide me how to do this?  It would be of great help.

 

Many thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/104105-select-first-2-letters-from-sql-table/
Share on other sites

You'll want some sort of separation such as placing a hyphen between the manufacturer's 2/3 character code and the model #, so your items would be

 

HTS-xxxxxx and ST-xxxxxx

 

Then you can run something like:

SELECT SUBSTRING_INDEX(model_no, '-', 1) as mft_code FROM Disks

Thanks guys,

 

I ran the code and it gave me the result:

 

mft_code

SP

IB

WD

SV

MP

6K

ST

6V

HT

FA

HD

MH

MH

MH

ST

ST

WD

HT

ST

HT

WD

....

 

How can I categorise them into different groups?  Like MH to Toshiba Group, ST to Seagate... etc...

It dont matter if its SQL or PHP as long as I am able to group them. 

 

Thanks guys for your help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.