views:

110

answers:

4

Hi guys.

I have a SQL query SELECT * FROM table WHERE column LIKE '%pdd%'.

The problem is I need to get all results excluding those which start with "pdd", I mean find everything where "pdd" is not at the beginning. How could it be done?

Thank you.

UPD. Sorry, I should've clarified my question a little bit more. I do need to match "pdd" except at the beginning of the column.

+1  A: 

Try:

SELECT * FROM table WHERE column NOT LIKE 'pdd%'
cinqoTimo
The OP seems to want to match 'pdd', except at the start of the column - this will not do that...
martin clayton
read for comprehension
fuzzy lollipop
+9  A: 

I assume you mean all rows that match "pdd" except those where "pdd" is at the beginning.

SELECT * FROM table WHERE column LIKE '_%pdd%'.

The "_" wildcard in LIKE predicates means "one of any character," equivalent to "." in regular expressions.

Bill Karwin
+2  A: 

If I understand your requirement correctly what you need is:

SELECT * FROM table WHERE column LIKE '%pdd_%' and column NOT LIKE 'pdd_%'
quosoo
A: 
SELECT * FROM table WHERE column LIKE '%pdd%' AND column NOT LIKE 'pdd%'

You can optimise the query depending on how frequent these occurrences are in your table.

Marc