Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Combining Multiple Tables Having Count Expand / Collapse
Author
Message
Posted Sunday, April 21, 2013 8:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 13, 2013 8:55 PM
Points: 18, Visits: 68
Hello,

I am trying to combine multiple tables, and then show only when value [Qry] when it is greater than 1 after combining the tables, below is what i wrote but not working.. thanks for your help in advance

select [Dm],[Qry],[AP]

from

(select [DM],[Qry],[AP]
from [dbo].[MyTable1]

union

select [DM], [Qry],[Ap]
from [dbo].[MyTable2]

union

select [dm],[Qry],[Ap]
from [dbo].[MyTable3]

) as ALL_MY_Tables

having count ([Qry])>1
Post #1444799
Posted Sunday, April 21, 2013 9:33 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 4:06 AM
Points: 1,917, Visits: 19,596
VegasL (4/21/2013)
Hello,

I am trying to combine multiple tables, and then show only when value [Qry] when it is greater than 1 after combining the tables, below is what i wrote but not working.. thanks for your help in advance

select [Dm],[Qry],[AP]

from

(select [DM],[Qry],[AP]
from [dbo].[MyTable1]

union

select [DM], [Qry],[Ap]
from [dbo].[MyTable2]

union

select [dm],[Qry],[Ap]
from [dbo].[MyTable3]

) as ALL_MY_Tables

having count ([Qry])>1


uneducated guess....


SELECT dm, COUNT(qry) AS Expr1
FROM (SELECT dm, qry
FROM MyTable1
UNION
SELECT dm, qry
FROM MyTable2
UNION
SELECT dm, qry
FROM MyTable3) AS x
GROUP BY dm
HAVING (COUNT(qry) IS NOT NULL)


______________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
Post #1444803
Posted Sunday, April 21, 2013 1:35 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 12:47 PM
Points: 164, Visits: 95
"show only when value [Qry] when it is greater than 1 after combining the table"

you need not use a aggregate function to achieve this.

HAVING [Qry] > 1 will work.
Post #1444817
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse