Chapter 9 . SQL According to MySQL 227 (Web hosting services)
Chapter 9 . SQL According to MySQL 227 Frequently I have to test a SELECT statement. For example, I might have the WHERE portion of the statement wrong, or a typo may crop up elsewhere in the statement. I also frequently work with fairly large tables that hold millions of records. Thus the LIMIT keyword has helped me countless times. Using LIMIT, I can set the SELECT statement to only return a subset of the results, thus potentially saving me from running a large and long query on a huge table. Figure 9-55: The results from some mathematical grouping functions Looking at one of the previous COUNT examples, if you wanted to order the results you could use the ORDER BYfunction. The ORDER BY function can sort the results in either ascending or descending order through the use of the ASC or DESCkeywords. In addition, you can use the HAVINGkeyword for even further parsing of results from a GROUP BY clause. I ll expand on some earlier examples here (and show the results in Figure 9-56): SELECT user,COUNT(user) FROM user GROUP BY user ORDER BY COUNT(user) DESC; SELECT user,COUNT(user) FROM user GROUP BY user ORDER BY user ASC LIMIT 3; SELECT user,COUNT(user) FROM user GROUP BY user HAVING user = suehring ;
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.