I have two queries pulling information from the same schema which I am joining together to create a single table. However, I need one of the resulting columns. In the example below I need the second 'owneridname' column to be removed from the results.
Current results:
owneridname | Yes | owneridname | No |
---|---|---|---|
Name1 | 230 | Name1 | 400 |
Name2 | 345 | Name2 | 546 |
Name3 | 87 | Name3 | 2345 |
Should be:
owneridname | Yes | No |
---|---|---|
Name1 | 230 | 400 |
Name2 | 345 | 546 |
Name3 | 87 | 2345 |
SELECT *
FROM
(
SELECT owneridname, COUNT(owneridname) AS 'Yes' FROM incident
WHERE svb_contactname IS NOT NULL
AND sub_caseinitiatedfrom IN ('1', '2', '3', '4', '16', '17')
AND sub_status_case IN ('1','2','12')
GROUP BY owneridname
) as FirstSet
INNER JOIN
(
SELECT owneridname, COUNT(owneridname) AS 'No' FROM incident
WHERE svb_contactname IS NULL
AND sub_caseinitiatedfrom IN ('1', '2', '3', '4', '16', '17')
AND sub_status_case IN ('1','2','12')
GROUP BY owneridname
) as SecondSet
on FirstSet.owneridname = SecondSet.owneridname
ORDER BY FirstSet.Yes DESC;
When I insert 'owneridname' into the first SELECT statement I get an error of "Msg 209, Level 16, State 1, Line 1 Ambiguous column name 'owneridname'." Not sure why it think it is an ambiguous column name?