/*This SQL script uses Demos.abs database. 
  Please open AbsoluteDatabase\Demos\Data\Demos.abs database file.
  This sample demonstrates use of subquery representing a separate field. 
  For each entry in table "Venues" the query counts quantity of events from table "Events" and places this number in a column named "EventsCount".*/

select v1."Venue", 
  (select count(*) from "Events" e1 where e1."VenueNo" = v1."VenueNo") as "EventsCount"
  from "venues" v1
 order by "EventsCount" desc
