isaac_cm Posted September 1, 2007 Share Posted September 1, 2007 I am trying to make the where clues like this where (f1 + f2 like "%red%") the problem it is working only if I write any value is part of field f1 and never return any record if I write value from field f2 any Ideas ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/ Share on other sites More sharing options...
teng84 Posted September 1, 2007 Share Posted September 1, 2007 where f1 like '%red%' or f2 like '%red%' better i guess and easier Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339059 Share on other sites More sharing options...
isaac_cm Posted September 1, 2007 Author Share Posted September 1, 2007 do you think I can use concat function ? Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339367 Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 if f1 contains "butter" and f2 contains "edam", do you want to include that record in the results? Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339751 Share on other sites More sharing options...
isaac_cm Posted September 2, 2007 Author Share Posted September 2, 2007 I just want if I write the word "am" I get that record because it is part of f2, and why plus sign "+" dont work !!! Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339761 Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 "+" is arithmetic addition operator. [pre] f1 | f2 | ---------+------------+ ham | x | y | spam | culpa | mea | [/pre] SELECT * WHERE CONCAT(f1, f2) LIKE '%am%' will return all 3, if that is the result you want. Teng's version SELECT * WHERE f1 LIKE '%am%' OR f2 LIKE '%am%' will return the first 2. Depends on how you want it Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339768 Share on other sites More sharing options...
isaac_cm Posted September 2, 2007 Author Share Posted September 2, 2007 Thanks to all of you I will use the Teng's version because not the two fields are one word and I think I know why + work only with f1 not f2 I think the query return ascii code numbers of the characters in f2 because of using +, right ?. Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339788 Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 If you SELECT (f1 + f2) as x FROM tablename you can see what it returns Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339791 Share on other sites More sharing options...
isaac_cm Posted September 2, 2007 Author Share Posted September 2, 2007 I got some records contains only zeros Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-339827 Share on other sites More sharing options...
fenway Posted September 4, 2007 Share Posted September 4, 2007 I got some records contains only zeros What? Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-341542 Share on other sites More sharing options...
isaac_cm Posted September 4, 2007 Author Share Posted September 4, 2007 hello fenway I have my table like that main(varchar) sub(varchar) result of using "+" ------------ --------------- ------------------ 10 Red 10 10 Blue 10 12 Green 12 Red null 0 Blue null 0 White null 0 as you see I get zeros !! Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-341640 Share on other sites More sharing options...
fenway Posted September 6, 2007 Share Posted September 6, 2007 So why use +? Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-343322 Share on other sites More sharing options...
isaac_cm Posted September 7, 2007 Author Share Posted September 7, 2007 I thought I could use + to search inside the two fields like that (f1 + f2 like "%red%") however I understand now it wont work Quote Link to comment https://forums.phpfreaks.com/topic/67514-solved-using-two-fields-with-like/#findComment-343366 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.