Abishek
Abishek

Reputation: 11691

Grouping in MySQL with a Not condition

I have a table browsers_list that has the following data.

name
--------------
Internet Explorer 8.0
Internet Explorer 9.0
Internet Explorer 10.0
Internet Explorer 11.0
Firefox 9.0.1
Firefox 6.0.2
Firefox 3.6.27
Safari 533.1
Safari 534.48.3
Safari 534.54.16
Opera 9.80
Chrome x.x.x
Chrome x.x.x
Chrome x.x.x

I require to group this list so that I get the following output.

name
--------------
Internet Explorer 8.0
Internet Explorer 9.0
Internet Explorer 10.0
Internet Explorer 11.0
Firefox
Safari
Opera
Chrome

How can i achieve this?

Upvotes: 0

Views: 54

Answers (1)

JodyT
JodyT

Reputation: 4412

Something like, though this is in a different order:

SELECT 
    CASE
      WHEN Name LIKE 'Internet Explorer%' THEN Name
      ELSE SUBSTRING_INDEX(Name, ' ', 1)
    END AS NewName
FROM TableA
GROUP BY NewName

Upvotes: 4

Related Questions