         let columns = render(columns: dataset, aliases: aliases)
         let source = dataset.render(dialect: self, aliases: aliases)
         
-        let ssql = "SELECT " + columns + " FROM " + source
-        let fsql = filter.render(dialect: self, aliases: aliases)
-        
-        let sql = ssql + (fsql.map {" WHERE " + $0 + ";"} ?? SQL(query: ";", parameters: []))
+        let base = SQL(query: "SELECT", parameters: [])
+        let ssql:SQL? = columns + " FROM " + source
+        let fsql = filter.render(dialect: self, aliases: aliases).map {"WHERE " + $0}
+        let lsql = limit.map(render)
+        
+        let sql = [ssql, fsql, lsql].flatMap {$0}.reduce(base) { z, a in
+            z + " " + a
+        }
         
         let paramsFixed = sql.parameters.map { param -> Any? in
             param.map { value in

        let dataset = ErasedTable(name: self.dataset.name, columns: .list(f(self.dataset)))
        return QueryImpl(dataset: dataset,
                         predicate: predicate,
                         order: order)
    }
    
    public func map(_ f: @autoclosure (DS)->String) -> QueryImpl<ErasedTable> {
        let dataset = ErasedTable(name: self.dataset.name, columns: .list([f(self.dataset)]))
        return QueryImpl(dataset: dataset,
                         predicate: predicate,
                         order: order)
    }
}


        
        return QueryImpl(dataset: ErasedTable(name: from, columns: columns),
                         predicate: nil,
                         order: "",
                         limit: nil)
    }
    
    public static func table(name: String) -> QueryImpl<ErasedTable> {
        return QueryImpl(dataset: ErasedTable(name: name, columns: .all),
                         predicate: nil,
                         order: "",
                         limit: nil)
    }
}

