|  | Posted by Erland Sommarskog on 06/20/06 22:04 
Jeff Kish (kishjjrjj@charter.net) writes:> How would I add the attribute column so I know exactly which ones are
 > of interest? That was what is the most difficult thing for me to
 > figure out.
 
 Not sure that I understood your original question, but try:
 
 SELECT a.object, a.attribute, a.keyseq
 FROM   metatable a
 JOIN   (SELECT object, keyseq
 FROM   metatable
 WHERE  keyseq IS NOT NULL
 GROUP  BY object, keyseq
 HAVING COUNT(*) > 1) AS b ON a.object = b.object
 AND a.keyseq = b.keyseq
 
 The thing in parenthesis is a derived table. You could think of a
 derived table as a temp table within the query, but never materialised.
 Or even computed, the optimizer may recasts the computation order
 to get performance. This is a great tool to write complex queries
 effeciently.
 
 And, yes, this is ANSI-SQL that should run on most RDBMS. (It's not
 as vintage as HAVING though.)
 
 --
 Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
 
 Books Online for SQL Server 2005 at
 http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
 Books Online for SQL Server 2000 at
 http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
  Navigation: [Reply to this message] |