Click here to Skip to main content
15,885,915 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all
SQL
SELECT
GROUP_CONCAT(LT.TAG_TEXT) AS TAGS
FROM M_OBJECT_TAG_MAPPING MOTM
INNER JOIN LK_TAG LT ON MOTM.FK_TAG_ID = LT.PK_ID
WHERE MOTM.OBJECT_TYPE= 1 AND MOTM.IS_ACTIVE = 1
GROUP BY MOTM.FK_OBJECT_ID HAVING (TAGS LIKE '%US%')

This is showing result
US,SharePoint,Avenger
Australia,Sambalpur
Usa,Flex,Asp.Net,Uk
Australia,US

but i want the result should be
Australia,US
US,SharePoint,Avenger


This is showing result having 'us' in them actually i want only US present in the tag.

Please help so that i will get the second result

Thanks in advance
Posted

1 solution

Consider different 3 cases.
First US at first: Here use 'US,%'
Second US at middle: Here use '%,US,%'
Finally US at last: Here use '%,US'

Thus change your Having clause as
SQL
HAVING (TAGS LIKE 'US,%' OR TAGS LIKE '%,US,%' OR TAGS LIKE '%,US')


Hope this will help :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900