218 Part II . SQL Essentials Figure 9-46: (Web hosting)

218 Part II . SQL Essentials Figure 9-46: The STRCMP function compares strings and returns an integer value based upon the results. Other methods exist for comparing strings in MySQL. Most notable is the LIKE function. The syntax for the LIKE function is different from the others that I ve been covering in the sections on SELECT and WHEREfunctions. As with the other functions that utilize parentheses for their arguments, the LIKEfunction compares the strings much like an equals sign (=) would. However, the LIKE function matches a pattern instead of a just a literal string. SELECT string1 LIKE string1 ; SELECT string1 LIKE string_ ; The LIKE function returns 1 if the comparison matches or 0 otherwise. The power of LIKE really emerges with the use of wildcards such as the underscore and the percent sign, as shown in Figure 9-47. Further, the LIKEfunction is most used in the WHERE portion of a SELECTstatement for non-exact matches. SELECT user,host FROM user WHERE user LIKE sueh% ; If you want to match a literal percent sign or underscore in a pattern, be sure to escape the percent with a backslash. For example, if I wanted to find a value that contained a percent sign, I can query for that by adding a backslash before the percent sign, like this: SELECT user,host FROM user WHERE host LIKE 192.168.1.% ;
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Leave a Reply