union-all

UNION with different data types in db2 server

I have built a query which contains UNION ALL, but the two parts of it have not the same data type. I mean, i have to display one column but the format of the two columns, from where i get the data have differences. So, if i get an example : select a,b from c union all select d,b from e a and d are numbers, but they have different f...

Does NHibernate HQL support the UNION ALL keyword?

After extensive googling, I still can't find a definitive answer to this question. Some old articles/blog posts I've seen say not at all. Some say yes if the underling database supports it. Which is it? I asked on the nhusers group with no answer so far. Any help would be appreciated. ...

Which Union ALL approach should be used?

We have 15 audit trail tables that need to be combined to look for inventory adjustments with certain criteria only. Is it best to do a UNION ALL with all tables, and then filter for criteria, OR throw the criteria into the mix on each table before doing a UNION ALL? Each table is only a few thousand records and the final filtered list...

Union on two tables with a where clause in the one

Currently I have 2 tables, both of the tables have the same structure and are going to be used in a web application. the two tables are production and temp. The temp table contains one additional column called [signed up]. Currently I generate a single list using two columns that are found in each table (recno and name). Using these two ...

SELECT table name that is inside UNION

I have two same tables. I need to union them in such way: SELECT f1,f2, xxx FROM (SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2) where xxx would query for a table name, where f1 and f2 fields are taken from. Example output: 123 345 'tbl1' -- this rows are from the first table 121 345 'tbl1' 121 345 'tbl1' 1...

Does table1 UNION ALL table2 guarantee output order table1, table2?

SELECT a FROM b UNION ALL SELECT a FROM c UNION ALL SELECT a FROM d Does UNION ALL guarantee to print out records from tables b, c, d in that order? I.e., no records from c before any from b. This question is not for a specific DBMS. ...

performance of union versus union all

I have to run a select statement across several tables. I am sure the tables return different records. I am anyway using UNION ALL. Is it better to use UNION or of UNION ALL in performance terms when I am sure the tables return different records? ...

MySQL: Optimizing SELECT from 6 huge identical tables with different data split up by timestamp

Hello, please I have the same problem as I found here http://stackoverflow.com/questions/409705/mysql-selecting-data-from-multiple-tables-all-with-same-structure-but-different , I have to select data from many MySQL tables with identical structure, but different data (split up into table_0, table_1, table_2 etc to table_5 to distribute...

SQL Server: ORDER BY in subquery with UNION

i have two queries being combined with a UNION ALL1: --Query 1 SELECT Flavor, Color FROM Friends   --Query 2 SELECT Flavor, (SELECT TOP 1 Color FROM Rainbows WHERE Rainbows.StrangerID = Strangers.StrangerID ORDER BY Wavelength DESC ) AS Color FROM Strangers Both of which, of course, work fine separately, but ...

T-SQL UNION query to return items with highest and lowest rating from the same table

I want write a stored proc in T-SQL to return the top 5 most highly rated and the bottom 5 most lowly rated articles from an Articles table, determined by the 'rating' column. I was thinking of using a union on two selects but I'm not sure how to write it. ...

UNION ALL, TEXT field and ORDER BY error

Hi, Im having two tables with attributes like date(datetime),headline(varchar),text(text) Now i want to UNION ALL these two tables and sort by the datetime. When doing this i'm getting the error: Only text pointers are allowed in work tables, never text, ntext, or image columns. The query processor produced a query plan that requir...

Should I use a T-SQL function, view, or stored proc ?

Hi Guys, I've got a question about reusing table data but a view won't work in this scenario as I have a parameter that needs to be passed in. Basically this part of the system requires a travellerid to be sent to the procedure and a list of arrangers returned for that specific traveller. There are around 7 business rules that are used ...

PHP: Display rows value same with all union limit

<? // Connect database include("cat-config.php"); // Get all records in all columns from table and put it in $result. $result=mysql_query(" (select * from stok_lukisan where `Ukuran` LIKE '20x25' AND `Kategori` LIKE '1' ORDER BY `Kode` ASC limit 3) union all (select * from stok_lukisan where `Ukuran` LIKE '3...

To union or union all, that is the question...

I have two queries that I'm UNIONing together such that I already know there will be no duplicate elements between the two queries. Therefore, UNION and UNION ALL will produce the same results. Which one should I use? ...

Adding column contents in a SQL UNION query

So far I have this query SELECT COUNT(f.code_id) as item_count, f.code_desc FROM foo f INNER JOIN foohistory fh ON f.history_id = fh.history_id WHERE MONTH(fh.create_dt) = 6 AND YEAR(fh.create_dr) = 2010 GROUP BY f.code_desc UNION ALL SELECT COUNT(b.code_id) as item_count, b.code_desc FROM ...