onedumbcoder Posted May 21, 2008 Share Posted May 21, 2008 Hi guys, lets say I have table with a field called code. is it possible to do a query where I look at the values in code and see if a patter occurs? for Example code = "ABCDE" and I want to see if CDE occurs in there and if so get it, so something like this: "select * from paper WHERE code has pattern CDE" Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/ Share on other sites More sharing options...
jonsjava Posted May 21, 2008 Share Posted May 21, 2008 SELECT * FROM paper WHERE code LIKE '%CDE%'; Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546542 Share on other sites More sharing options...
onedumbcoder Posted May 21, 2008 Author Share Posted May 21, 2008 is it possible to determine where the nth element is lets say C? for example select * from paper where code[nth] = 'C'? Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546616 Share on other sites More sharing options...
effigy Posted May 21, 2008 Share Posted May 21, 2008 SUBSTR Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546618 Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 Quite the ultra-difficult question. Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546621 Share on other sites More sharing options...
onedumbcoder Posted May 21, 2008 Author Share Posted May 21, 2008 so this would work? select * from paper WHERE SUBSTRING(code, -1, 1)= 'C' Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546703 Share on other sites More sharing options...
rhodesa Posted May 21, 2008 Share Posted May 21, 2008 select * from paper WHERE SUBSTRING(code, -1)= 'C' The last argument is not needed. But the that would return anything where the value of code ends with a C. This produces the same result: select * from paper WHERE code LIKE '%C' Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546707 Share on other sites More sharing options...
onedumbcoder Posted May 21, 2008 Author Share Posted May 21, 2008 Thanks for all the help so far. I understand % means anything goes: for example %C get everything that ends with C C% ... that starts with C And I guess I could even do %C%C%? Are there any one symbols used besides %? if so can you please mention them and their influence. Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-546840 Share on other sites More sharing options...
sasa Posted May 22, 2008 Share Posted May 22, 2008 _ replace one caracter Quote Link to comment https://forums.phpfreaks.com/topic/106630-a-query-with-a-pattern-match-condition/#findComment-547158 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.