November 15, 2013 at 6:11 am
Guys,
I would like to combing the following:
1. Retreive the results from SQL 1
2. Retreive the results from SQL 2
3. Remove SQL 2 results from SQL 1 results
4. Select specific rows from the final set of SQL1 results.
Hope this makes sense??? Any help much appreciated.
SQL1
Select col1, col2, count (*)
from table a
where col3 is null
GROUP BY col1, col2,
HAVING count(*) >1
minus
Sql2
select *
from table b
left outer join table c
on b.col1 = c.col1
Many thanks
L
November 15, 2013 at 6:35 am
the EXCEPT operator can do that, but the number /types of columns must be the same in both queries.
otherwise, show us your real queries instead of pseudocode, and we can get you pointed int he right direction.
Select col1, col2, count (*)
from table a
where col3 is null
GROUP BY col1, col2,
HAVING count(*) >1
EXCEPT
Select col1, col2, count (*)
from table b
left outer join table c
on b.col1 = c.col1
Lowell
November 15, 2013 at 6:56 am
Hi Lowell, thanks for the response. It doesn't appear to work. I get "SQL command not properly ended" error?
FYI
Select l.add, l.phne
from e_lkup l
where mins is null
GROUP BY phne, add
HAVING count(*) >1
EXCEPT
select l.add, l.phne (error on this line)
from s_status ss
left outer join e_lkup l
on l.mcs = ss.mcs
November 15, 2013 at 7:09 am
This is a SQL Server forum. Are you sure you're not using Oracle?
John
November 9, 2015 at 5:28 am
November 9, 2015 at 11:04 am
In SQL Server, you'd need brackets around the name "Add":
Select l.[add], l.phne
from e_lkup l
where mins is null
GROUP BY phne, [add]
HAVING count(*) >1
EXCEPT
select l.[add], l.phne
from s_status ss
left outer join e_lkup l
on l.mcs = ss.mcs
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply