Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

How I can compare two rows?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How I can compare two rows?

    José Juan wrote: > SELECT MIN(tableName) as TableName, id, col1,col2,col3 > FROM > ( > SELECT tablea as tableName,a.id,a.col1,a.col2,a.col3 > FROM A > UNION ALL > SELECT tableb as tableName,b.id,b.col1,b.col2,b.col3 > FROM B > ) tmp > GROUP BY id,col1,col2,col3 > HAVING count(*) = 1 > ORDER BY id Jose, Try using one of the most powerful features of SQL I've seen: WITH. With twotables (tablename, id, col1, col2, col3) as (Select tablea, id, col1, col2, col3 From A Union All Select tableb, id, col1, col2, col3 From B) Select Min(tablename) as tablename, id, col1, col2, col3 From twotables Group by id, col1, col2, col3 Having count(*) = 1 Order by id The above is all one statement. Basically, the With statement creates a view on the fly. Bill

  • #2
    How I can compare two rows?

    Hi!. I have an issue. I need to compare two rows between two tables with the same structure (same attributes) but in different library (schema). I am in v5r1 and this example does not work: SELECT MIN(tableName) as TableName, id, col1,col2,col3 FROM ( SELECT tablea as tableName,a.id,a.col1,a.col2,a.col3 FROM A UNION ALL SELECT tableb as tableName,b.id,b.col1,b.col2,b.col3 FROM B ) tmp GROUP BY id,col1,col2,col3 HAVING count(*) = 1 ORDER BY id

    Comment

    Working...
    X