oficial de marina, blanco
oficial de marina, azul claro
capitan de tierra, marrón talla 4
capitan de tierra, marrón talla 6
En el ejemplo que mandas es fàcil ya que la coma esta en la misma posición en los dos casos (digito 18) luego
Select distinct
left(nombreCampo
, 17) from nombreTabla
Pero claro para
soldado raso, caqui
No te funcionará.... y en general si la coma no esta siempre en el mismo lugar...
En este caso deberas usar lo siguiente
Select distinct
left(nombreCampo
, instr(nombreCampo
,",")-1) from nombreTabla
Del manual de MySQL
Cita: LEFT(str,len)
Returns the leftmost len characters from the string str, or NULL if any argument is NULL.
mysql> SELECT LEFT('foobarbar', 5);
-> 'fooba'
INSTR(str,substr)
Returns the position of the first occurrence of substring substr in string str. This is the same as the two-argument form of LOCATE(), except that the order of the arguments is reversed.
mysql> SELECT INSTR('foobarbar', 'bar');
-> 4
mysql> SELECT INSTR('xbar', 'foobar');
-> 0
This function is multi-byte safe, and is case sensitive only if at least one argument is a binary string.
Quim