tags:

views:

38

answers:

3

I want to select records in my table when it matches a row that ends with a particular value.

eg.

if 'oop' is found at the end of a particular record it select the record

Pls how can i go about it

thanks

+2  A: 

You can use LIKE:

SELECT *
FROM your_table
WHERE your_column LIKE '%oop'

Note that this query will result in a full scan so it might be slow if you have many rows.

Mark Byers
before i saw ur post, i came up with this: select from table where substring('columnname', -(length('oop')))='oop'. will it do the same job? if it will which will u advise. thanks
Ogugua Belonwu
+1  A: 
select * from yourtable where somevalue like '%oop'
Alex
before i saw ur post, i came up with this: select from table where substring('columnname', -(length('oop')))='oop'. will it do the same job? if it will which will u advise. thanks
Ogugua Belonwu
If you are OK with implementing your own solution in favor of a simple, concise answer suggested by several people in this thread, as well as taking the performance hit of multiple function calls, then yes, your answer is perfect.
Alex
thanks alex, actually what prompted my statement is this line: 'Note that this query will result in a full scan so it might be slow if you have many rows.' from Mark Byers. What am looking at is the performance. Hope u will understand my point of view, thanks once again
Ogugua Belonwu
A: 
SELECT *
FROM your_table
WHERE your_column REGEXP 'oop'

Regular Expression Queries can open up some pretty cool extra features that like can't touch.

bpeterson76