Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select last word in a string. 1

Status
Not open for further replies.

petrosky

Technical User
Aug 1, 2001
512
AU
Hi,

I have a SQL statement that currently selects the left most word of a Description field to return a brand only.

Some products have the brand as the last word in the Description field.

How would I go about selecting the Last word? Should I be approaching this from PHP?

Here is the Left which works for the first word...

Code:
SELECT Left(Description, INSTR(Description, ' ')-1 as Brand

Any ideas appreciated.

Peter.

Remember- It's nice to be important,
but it's important to be nice :)
 
try
Code:
 select reverse(left(reverse(Description), instr(reverse(Description),' ') -1)) from <table>

 
ingresman, that's cute, but harley's suggestion is so much cleaner and simpler

SELECT SUBSTRING_INDEX(Description,' ',-1) as Brand

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Thank you all for your help.

Kind regards,

Peter.

Remember- It's nice to be important,
but it's important to be nice :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top