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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a select

Status
Not open for further replies.

letimati

Technical User
Feb 3, 2006
36
GB
Hi I have a table with peoples names in it like so.

table
name
--------
John Smith
Adam J Simpson
Simon
Alex 3rd of kingdom 2 Smith

I want to select all the rows where the last word starts with 'S' i.e. an alphabet search on the last name.

I was trying to use somthing like

WHERE name REGEXP '[[:<:]]s[[:alnum:]]'

which i think means a word starting with 's' which only has letters after it.

Basically my thinking is find a word tht starts with a 's' that has no spaces after it, which would mean thats the last word.

I am going a few other trys but thought i would post in case this is in fact easy.

thanks in advance for any time taken by you.
 

Try:

Code:
SELECT ...
 WHERE SUBSTR(NAME, INSTR(NAME,' ',-1)+1,1) = 'S'
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
This works and also lets you order on the last work as well


WHERE REVERSE( SUBSTRING_INDEX( REVERSE( name ) , ' ', 1 ) ) LIKE 'S%'
ORDER BY REVERSE( SUBSTRING_INDEX( REVERSE( name ) , ' ', 1 ) )
 

Sorry I gave you the "Oracle" version. [thumbsdown]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
No problem it got me looking in the right direction anyway so thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top