Hey guys I'm trying to join together two queries and am having an issue,
maybe you can take a look, I have these two separate queries i'm trying
to combine. There is a third join that will be in there to get a field
that will count how many parents it also has which I haven't started on.
I came up with this, but am having issues with itCode:SELECT e.baseName AS baseName, s.baseName AS masterName FROM dataSet e INNER JOIN dataSet s ON s.id = e.entityId ORDER BY e.entityId SELECT e.baseName AS baseName, b.baseName AS masterName, COUNT(*)-1 AS siblingCount FROM dataSet e JOIN dataSet b ON b.id=e.entityId GROUP BY b.id, b.baseName
Table structure is like soCode:SELECT e.baseName AS baseName, s.baseName AS masterName, COUNT(*)-1 AS siblingCount FROM dataSet e JOIN dataSet b ON b.id = e.entityId INNER JOIN dataSet s ON s.id = e.entityId GROUP BY b.id, b.baseName ORDER BY e.entityId
Code:+----+--------------------+----------+ | id | baseName | entityId | +----+--------------------+----------+ | 1 | 000000000000000001 | 1 | | 2 | 000000000000000002 | 1 | | 3 | 000000000000000003 | 1 | | 4 | 000000000000000004 | 2 | | 5 | 000000000000000005 | 2 | | 6 | 000000000000000006 | 2 | | 7 | 000000000000000007 | 2 | | 8 | 000000000000000008 | 2 | | 9 | 000000000000000009 | 3 | | 10 | 000000000000000010 | 3 | | 11 | 000000000000000011 | 3 | | 12 | 000000000000000012 | 3 | | 13 | 000000000000000013 | 3 | | 14 | 000000000000000014 | 3 | | 15 | 000000000000000015 | 3 | | 16 | 000000000000000016 | 4 | | 17 | 000000000000000017 | 4 | | 18 | 000000000000000018 | 4 | | 19 | 000000000000000019 | 4 | | 20 | 000000000000000020 | 4 | +----+--------------------+----------+
What I'm really looking for is this
Code:+--------------------+--------------------+--------------+-------------+ | baseName | masterName | siblingCount | parentCount | +--------------------+--------------------+--------------+-------------+ | 000000000000000001 | 000000000000000001 | 2 | 0 | | 000000000000000002 | 000000000000000001 | 4 | 1 | | 000000000000000003 | 000000000000000001 | 4 | 1 | | 000000000000000004 | 000000000000000002 | 6 | 2 | | 000000000000000005 | 000000000000000002 | 4 | 2 | | .... | .... | .... | .... | +--------------------+--------------------+--------------+-------------+
Help would be appreciated


Reply With Quote
Bookmarks