There are 4 tables

-------------------- STORAGE -------------------- SCOPE | SCODE ---------|---------- MATERIAL | MATRLN001 GUIDELINE| GUINMK001 PROJECT | PRJDCS001 MATERIAL | MATRLN002 PROJECT | PRJDCS002 MATERIAL | MATRLN003 GUIDELINE| GUINMK002 PROJECT | PRJDCS003 GUIDELINE| GUINMK003 MATERIAL | MATRLN004 PROJECT | PRJDCS004 ----------------------- MATERIAL ----------------------- CODE | SECCODE | TAGID ----------------------- MAT | RLN001 | 2 MAT | RLN002 | 2 MAT | RLN003 | 1 MAT | RLN004 | 3 ----------------------- GUIDELINE ----------------------- CODE | SECCODE | TAGID ----------------------- GUI | NMK001 | 3 GUI | NMK002 | 2 GUI | NMK003 | 1 ----------------------- PROJECT ----------------------- CODE | SECCODE | TAGID ----------------------- PRJ | DCS001 | 3 PRJ | DCS002 | 3 PRJ | DCS003 | 2 PRJ | DCS004 | 2 

need to display TAGID and the number of its uses

Something like this:

 ------------- RESULT ------------- TAGID | COUNT ------------- 1 | 2 2 | 5 3 | 4 ------------- 

SCODE in STORAGE is created as SCODE = CODE || CHR(9) || SECCODE SCODE = CODE || CHR(9) || SECCODE

Became a dead end, I do not know how to overcome and come up with a request: (

    2 answers 2

     select TAGID,sum(cnt) cnt from ( select TAGID,count(1) cnt from MATERIAL group by TAGID union all select TAGID,count(1) from GUIDELINE group by TAGID union all select TAGID,count(1) from PROJECT group by TAGID ) group by TAGID 

    If you want, of course, you can still re-paste the whole thing with STORAGE, but why is it absolutely unclear when counting the amount in the TAGID section? And the structure of the base with three tables with the same structure and a kind of composite field in STORAGE is to say the least strange ...

      isn't it?

       SELECT TAGID, COUNT(TAGID) FROM PROJECT GROUP BY TAGID 

      So the principle of counting is not clear, how these 4 tables are related and why they are when counting tags