Common questionsHow do I use this knowledge on the web? How do I search for news newer than [a date]? SELECT * from news where newsDate<'#2003-01-01#' ORDER BY newsDate DESC It's the ## which does the magic. < means "less than" and > means "greater than". Figure it out! How do I search a field for a given string? SELECT * from news WHERE newsBody LIKE "%futurama%" The % signs are wildcards telling the database that there can be other text both in front of and after the search string. This query will return all news where the body contains the word futurama. How do I count news items? SELECT COUNT(*) from news where memberID=1 How do I figure out the average age of my members? SELECT AVG(memberAge) AS age from member Here I showcased the AS command too. This way you can name your results. This comes in handy when you select multiple (otherwise) nameless variables. In the following examples, utilizing some other nice functions in SQL, using no naming simply wouldn't be appropriate (it would still work though): SELECT AVG(memberAge) AS average, MIN(memberAge) AS youngest, MAX(memberAge) AS oldest FROM member That's it! Final wordsThis has been one crazy night for me. My hands hurt from all the typing and I would really appreciate if you told me if you liked the article or have anything to add about it. My email at thec@home.se is always open for your comments and I'd love to hear from you. I hope this article has given you something to build on and that it has been some pleasant reading. SQL is really a powerful tool to know, and the more you know, the more fun it will be. There are many aspects of SQL which I haven't shown here. Perhaps I'll write another article some time, only time can tell. Thank you for your time. About the authorYou're going to be surprised. Although I love electronics and know a lot of programming in many senses and have been studying programming at the university for a while, I'm a tile layer. That's like a bricklayer only that I just do the tiles part. That is, I do bathrooms, kitchens, floors and balconies and such. Please check my homepage www.thec.org for some pictures and extended information about myself. During a couple of years in the industry and lots of home programming I mostly program/manage hobby sites and such, as well as doing some C++ code when I lose my mind... sorry, I mean am in the right mood for it! Other than computers, I love cars and snowboarding, so that's basically my real life activities. |
|