Link to home
Start Free TrialLog in
Avatar of freshwaterwest
freshwaterwestFlag for United Kingdom of Great Britain and Northern Ireland

asked on

mysql select value where contains string but not with space after

I'm really stuck on something which is probably really easy...so apologies in advance!

I have a column which can contain any of the following for instance:

Thin
or
Super Thin
or a set of values with pipe delimiters
Thin||Super Thin||Other Value||Another Value

I want to select only occurrences of Thin but not Super Thin

I've tried LIKE AND NOT LIKE but this doesn't seem to work:

SELECT value FROM table_name WHERE value LIKE "%Thin%" AND value NOT LIKE "%Super Thin%"

Also looked into REGEXP but not sure how to use in this case.

many thanks


SOLUTION
Avatar of pdd1lan
pdd1lan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freshwaterwest

ASKER

Hi pdd1Ian, thanks for reply, I'm trying to show a list of features for a product so a product might have just "Thin" or just "Super Thin" or both Thin||Super Thin

the problem is Thin is within both values (Thin and Super Thin) so I need to find a way to make sure it's just finding Thin

hope that makes sense..

thanks
ASKER CERTIFIED SOLUTION
Avatar of Bernie Bsen
Bernie Bsen
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdd1lan
pdd1lan

or also working as this way
--thin list
SELECT value
 FROM table_name
WHERE value  <>"Supper Thin"

--supper thin list
SELECT value
 FROM table_name
WHERE value  ="Supper Thin"
I can see that it all makes sense and should be working, but it doesn't work in my instance - I'm baffled - here's the details of a query I've tried:

tablename contents
id: 145792      
otherid: 20
contentid: 6536      
value: Glass||CR39||NXT||Thin||Super Thin

sql query:
SELECT value FROM tablename WHERE value LIKE "%Thin%" AND value NOT LIKE "%Super Thin%" AND contentid =  6536 AND otherid = 20

but result is nothing.

sql query:
SELECT value FROM modx_site_tmplvar_contentvalues WHERE value LIKE "%Thin%" AND contentid =  6536 AND tmplvarid = 20

gives me result:
Glass||CR39||NXT||Thin||Super Thin

as expected


sorry I left the actual table names etc in the last one by mistake just to confuse things even more!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for your help all - I have sussed out what my problem was, partly due to me not understanding how the LIKE returns the result and partly as I had both logos showing in both cases!

I'll share the points as all comments have been correct!