SQL Strategies and Tactics
July 20, 2010
Sorting By Count(*)
By Bryan Young
The other day, I was working on a fairly database-centric project, when I came across a problem I had never come across before. It seemed like such a simple task that I could not fathom why I could not write the query to get what I wanted. What I needed to do was to choose only the entries in a table which appeared a certain number of times.

My first instinct told me to do something like this.

SELECT COUNT(*), name FROM tableA GROUP BY name WHERE COUNT(*) > 10;

What do you mean "Invalid use of group function"? So I start investigating, and I find out that the count function cannot be used in the WHERE section of a query. This is because SQL will process the WHERE clause before the SELECT clause in order to know just what it is searching for.

Continue Reading
Interested in contributing to the SQL community?
Can you write expert articles and tutorials designed to help SQL users of any skill level implement successful SQL systems and practices? If so, we are looking for you. Contact techwriters@ientry.com.
Today's Top Videos:
Using Research to Understand Searchers
Although many online marketers spend time focusing on keywords, Chitika's CEO Venkat Kolluri says that search behavior research could actually do more to improve online marketing...
Yahoo Talks Merger, Global Branding, and Ad Development
As Yahoo and Microsoft continue to integrate the terms of their 10-year partnership, there are lots of questions surrounding Yahoo. To shed some light on this area, WebProNews...
Paid Search to Overtake Organic?
The organic and paid search dynamic has changed dramatically in recent years. With these changes, many people within the search industry have continued to maintain...
Recent Articles:
How To Dupe Duplicate Rows In Three Easy Steps
Repetitive information goes against good database design, and thus is reason enough to find and remove duplicate values. However, when utilizing an UNIQUE key or other types of indexes, duplications actually break or prevent statements from executing properly.

Step 1: Determine if duplicates exist.

mysql>SELECT value, count(*) as num

FROM t1

GROUP BY value
Read More...

Cooking With SQL: Short And Sweet
One of my fondest childhood memories revolves around my Grandmother's cooking. She was able to take out store bought hot dogs, boil them in a pot of water, and serve them up on piece of bread for many of my childhood lunches. Likewise, one my...
Read More...
A Uniform Query To The Community
The language of SQL is a lot like the English language. You have North American and Great Britain dialects of the language, not to mention significantly varying degrees of those dialects broken down amongst the geographical regions in which they're...
Read More...
Teradata Releases New Database Features
Todd Walters introduced the new release - 13.10. Not every feature is equally interesting to me but a couple were important to note: One of the key features in the new database release is the support for temporal tables. Default for a temporal...
Read More...
Other iEntry Business Resources:
- WebProNews.com
- Jayde.com
- MarketingNewz.com
- SalesNewz.com
- CareerNewz.com
- InvestNewz.com
- eCommNewz.com
- WebsiteNotes.com
- AdvertisingDay.com
iEntry
footer
-- SQLProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2010 iEntry, Inc. All Rights Reserved Privacy Policy Legal