That Other SQL Predicate

by Robert Munoz - GUI Computing
Image of Line Break

We’re all familiar with the standard VB/SQL predicates ALL, DISTINCT and DISTINCTROW. However, there is also a predicate named TOP that is supported by VBJet. If you are already familiar with this, then obviously you do not develop many database applications in VB.

You see, this lovely SQL predicate is not listed in our comprehensive and informative VB help file. Yet it is in Access, and I only stumbled across it by accident.

The word TOP is self evident and you would assume it returns the topmost record of a snapshot or dynaset. However TOP does more than this. You can specifically select the number of records to be returned, starting from the top. You can also return a percentage of the data set by specifying a percentage following TOP. Pretty handy...

  SELECT TOP 10 Name, Address FROM Customers WHERE Age>21, or
  SELECT TOP 10 PERCENT Name, Address FROM Customers WHERE Age>21

For more info do delve into the Access help file.

Written by: Robert Munoz
August 1995