SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Combining Multiple Tables Having Count


Combining Multiple Tables Having Count

Author
Message
VegasL
VegasL
SSC-Enthusiastic
SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)

Group: General Forum Members
Points: 100 Visits: 159
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
J Livingston SQL
J Livingston SQL
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5464 Visits: 35417
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

messages4kanthi
messages4kanthi
SSC-Enthusiastic
SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)

Group: General Forum Members
Points: 180 Visits: 159
"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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search