let (n,from,where) =
List.fold_left (add_constraint tables) (0,[],[]) metadata
in
+ let selected = if metadata = [] then count_tbl else "table0" in
let (n,from,where) =
add_all_constr count_tbl (n,from,where) concl_card full_card diff
in
let where = String.concat " and " where in
let query =
match rating with
- | None -> sprintf "select table0.source from %s where %s" from where
+ | None -> sprintf "select %s.source from %s where %s" selected from where
| Some `Hits ->
sprintf
- ("select table0.source from %s, hits where %s"
- ^^ " and hits.source = table0.source order by hits.no desc")
- from where
+ ("select %s.source from %s, hits where %s"
+ ^^ " and hits.source = %s.source order by hits.no desc")
+ selected from where selected
in
prerr_endline query;
let result = Mysql.exec dbd query in