...

View Full Version : UNION Query



mathceleb
06-15-2011, 10:48 PM
I have two tables, table1 and table2.

I want to select everything from table1 and a count of table 2.


SELECT a. *
FROM table1 a
UNION SELECT count(b.*) AS bct
FROM table2 b

This is not working. Any thoughts?

Old Pedant
06-15-2011, 11:35 PM
Read up on how UNION works: You must have the SAME number of fields and type of fields in all branches of the union.

In short, you don't want a union for this.

You might be best off simply making two separate queries. You could combine them into one, but if the data in the two tables are unrelated (as it seems to be), there's not much point.

mathceleb
06-15-2011, 11:44 PM
Read up on how UNION works: You must have the SAME number of fields and type of fields in all branches of the union.

In short, you don't want a union for this.

You might be best off simply making two separate queries. You could combine them into one, but if the data in the two tables are unrelated (as it seems to be), there's not much point.

They are completely unrelated. I just wrote two separate queries and that worked fine. Thanks for the tip!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum