I have three tables that SELECT
from and I'd need to join the results.
It feels like this should be a rather easy task but I struggle with the syntax.
Working on Microsoft SQL Server Enterprise Edition v9.00.3042.00, i.e. SQL Server 2005 Service Pack 2
What I came up with so far is..
TableA
hasid
(int),name
(varchar),comment
(varchar) andextra
(varchar).TableB
hasid
(int) andchar
(varchar)TableC
haseid
(int) andinfo
(varchar).
SQL query:
SELECT
b.count, a.id, a.name, a.comment
FROM
(SELECT *
FROM TableA a
WHERE id + 100 IN (SELECT distinct(eid)
FROM TableC
WHERE NOT eid IS NULL)
)
JOIN
(SELECT
char, count(*) AS count
FROM TableB b sel
GROUP BY char) on a.id + 100 = b.char
What I'd like to have is the output of the top select (TableA
) with the count of TableB
where a.id+100
is b.char
Excuse my amateur-ish sql..