How to combine 2 or more query results?

  • Union works if the data type is compatible and the number and order of the field must be identical.

    e.g combining result from these 2 query:

    select a, b, c from tablex

    select x,y,z from tablez

  • Or even if SQL can coerce the data types to match. Biggest mistake I see with union is that most people leave off the 'ALL' - not realizing that SQL will remove duplicate lines otherwise.

    Andy

  • You can also CAST columns to match each other.

    Steve Jones

    steve@dkranch.net

  • If you're using the results from these two queries in ADO, use NextRecordset to loop through one then the second result set.

  • Deuce - if you're using union you'll only get one recordset. In some cases returning multiple recordsets will make more sense...union won't work, you need it separated anyway, etc. Multiple recordsets are a great way to reduce round trips.

    Andy

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply