varchar(8) but want to group by only first 4

This is a discussion on varchar(8) but want to group by only first 4 within the MySQL Database forums, part of the Database Forums category; I have database table with varchar(8) column that is not key. It has value for example axF12b!h, axF17F!...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-05-2006
moleskyca1@yahoo.com
 
Posts: n/a
Default varchar(8) but want to group by only first 4

I have database table with varchar(8) column that is not key. It has
value for example axF12b!h, axF17F!h, axF12893, etc...

axF1 is always the same and I want to goup by this so I can count. How
to do this?

I have more than 3 million record. This is not index key. Will this be
too slow and mysql timeout?

Reply With Quote
  #2 (permalink)  
Old 12-06-2006
lain
 
Posts: n/a
Default Re: varchar(8) but want to group by only first 4


moleskyca1@yahoo.com wrote:
> I have database table with varchar(8) column that is not key. It has
> value for example axF12b!h, axF17F!h, axF12893, etc...
>
> axF1 is always the same and I want to goup by this so I can count. How
> to do this?
>
> I have more than 3 million record. This is not index key. Will this be
> too slow and mysql timeout?


SELECT substr(
column_name
FROM 1
FOR 4
) AS alias_name
FROM table_name
GROUP BY alias_name

on 3 million records it can be slow - can't you add some other
limitations to reduce number of rows to group?? or split it to parts??

Reply With Quote
  #3 (permalink)  
Old 12-07-2006
Jerry Stuckle
 
Posts: n/a
Default Re: varchar(8) but want to group by only first 4

moleskyca1@yahoo.com wrote:
> I have database table with varchar(8) column that is not key. It has
> value for example axF12b!h, axF17F!h, axF12893, etc...
>
> axF1 is always the same and I want to goup by this so I can count. How
> to do this?
>
> I have more than 3 million record. This is not index key. Will this be
> too slow and mysql timeout?
>


Yes, it will be slow.

The fact you don't have an index on this column means MySQL will need to
do a table scan. And the fact you're doing a string vs. integer
comparison means it will be even slower.

Adding an index for the column should help.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #4 (permalink)  
Old 12-08-2006
Willem Bogaerts
 
Posts: n/a
Default Re: varchar(8) but want to group by only first 4

> Adding an index for the column should help.

And you can give a string length with the index, so is you want to group
on the first 4 characters, you can try to add an index with length 4. If
this does not speed up the query, you might try the FORCE clause to
force MySQL using that index, or else the HANDLER statement.

Good luck.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0