0

I'm running a query to retrieve the first word from a string in a colum like so..

SELECT SUBSTRING_INDEX( `field` , ' ', 1 ) AS `field_first_word`FROM `your_table`

But this allows duplicates, what do I need to add to the statement to get unique list of words out?

2 Answers 2

1

DISTINCT

For example:

SELECT DISTINCT SUBSTRING_INDEX( `field` , ' ', 1 ) AS `field_first_word` FROM `your_table`

Note: There are performance implications for DISTINCT. However, in your case, there is likely limited pure MySQL alternatives.

Sign up to request clarification or add additional context in comments.

1 Comment

No worries. Enjoy tomorrow. Just 10pm here.
1

To remove duplicates in a SELECT statement, change to SELECT DISTINCT column. In this case:

SELECT DISTINCT SUBSTRING_INDEX( `field` , ' ', 1 ) AS `field_first_word`FROM `your_table`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.