r9657: Cleanup and document the FDDL.
[clsql.git] / sql / expressions.lisp
index f2d63c9c85c47e9dd810bce8dff46480291692d8..50aa5d1fd478942ec8dfdd6eebd15f6d1bb4d252 100644 (file)
@@ -578,15 +578,21 @@ uninclusive, and the args from that keyword to the end."
     (output-sql (apply #'vector selections) database)
     (when from
       (write-string " FROM " *sql-stream*)
-      (typecase from 
-        (list (output-sql (apply #'vector (remove-duplicates 
-                                          from 
-                                          :test #'(lambda (a b)
-                                                    (string-equal (symbol-name (slot-value a 'name))
-                                                                  (symbol-name (slot-value b 'name))))))
-                         database))
-        (string (write-string from *sql-stream*))
-        (t (output-sql from database))))
+      (flet ((ident-table-equal (a b) 
+               (and (if (and (eql (type-of a) 'sql-ident-table)
+                             (eql (type-of b) 'sql-ident-table))
+                        (string-equal (slot-value a 'alias)
+                                      (slot-value b 'alias))
+                        t)
+                    (string-equal (symbol-name (slot-value a 'name))
+                                  (symbol-name (slot-value b 'name))))))
+        (typecase from 
+          (list (output-sql (apply #'vector 
+                                   (remove-duplicates from 
+                                                      :test #'ident-table-equal))
+                            database))
+          (string (write-string from *sql-stream*))
+          (t (output-sql from database)))))
     (when inner-join
       (write-string " INNER JOIN " *sql-stream*)
       (output-sql inner-join database))