I have 2 tables.
tblparents
----------
parentid
husbandid
wifeid 
tblnode
-------
nodeid
personid
parentid
What i want is an SQL statement that gets parentid, husband/wifeid and the count of rows in tblnode where parentid's are equal.
I wrote the code
SELECT t.parentid, t.spouseid, t.active, c.count FROM    
(SELECT parentid, wifeid spouseid from tblparents WHERE husbandid=1
UNION
SELECT parentid, husbandid spouseid from tblparents WHERE wifeid=1) t 
INNER JOIN 
(SELECT COUNT(*) count FROM tblnodes WHERE tblnodes.parentid=t.parentid) c;
It gives an error #1054 - Unknown column 't.parentid' in 'where clause'.
Any ideas how to solve ?
Thanks a bunch,
                        
There was a syntax error. Try this:
However the following query will perform better: