I need help joining tables

user7983964

I need help on joining these three fields,

Party table where all party information stored: it just a list of Party Name and ID. and it look like this

PartyID PartyName
14      CIDS
15      DTL
16      CRTS
17      VIVAR
18      CT INC
19      AMC INC
20      YIBG
38      LLA INC
35      GFRC
43      UC AM    
44     CIDW
46       KIN TECH
47      MAIN RP
85      CCDS

I have this Responsible Party table as

  RPID  PID PartyID
   38   42   85

I have this subparty table

SPID    RPID PartyID
14      38    43
15      38    44
16      38    45
17      38    45
18      38    46
19      38    47
20      38    47

I need your help on displaying my data as

RPID    PartyID  PartyName  SubID   SubParty
38       43      UCAM       14      CIDS    
38       44      CIDW       15      DTL
38       45                 16      CRTS
38       45                 17      VIVAR   
38       46    KIN TECH     18     CT INC
38       47                 20      YIBG
38       85     CCDS        
forpas

You need to join subparty to responsibleparty and 2 copies of party:

select sp.rpid, sp.partyid, p.partyname, sp.spid, pp.partyname subparty
from subparty sp
left join responsibleparty rp on rp.rpid = sp.rpid
left join party p on p.partyid = sp.partyid
left join party pp on pp.partyid = sp.spid

See the demo.
Results:

> rpid | partyid | partyname | spid | subparty
> ---: | ------: | :-------- | ---: | :-------
>   38 |      43 | UC AM     |   14 | CIDS    
>   38 |      44 | CIDW      |   15 | DTL     
>   38 |      45 | null      |   16 | CRTS    
>   38 |      45 | null      |   17 | VIVAR   
>   38 |      46 | KIN TECH  |   18 | CT INC  
>   38 |      47 | MAIN RP   |   19 | AMC INC 
>   38 |      47 | MAIN RP   |   20 | YIBG 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

i need help on "this" keyword and inheritance

From Dev

I need help joining two queries to get one table as result

From Dev

While joining 2 tables, can i use *?

From Dev

need a true false answer for multiple conditions when joining two tables

From Dev

Need some help in joining two tables

From Dev

need help switching between tables in javascript

From Dev

I need help for building a regex

From Dev

I need Help Joining 2 onEdit function currently only the first one is working

From Dev

I need help in nodejs

From Dev

Joining tables with ` `

From Dev

I need Help Installing JDK

From Dev

I need help decoding this, is this json?

From Dev

Need to display records by joining two tables and the records should be Unique

From Dev

need help joining tables in sql

From Dev

i need help on .append

From Dev

Need help in merging three tables foreign keys

From Dev

I need help understanding this "for" loop

From Dev

Need help joining 2 tables and rolling them up in a unique way using BigQuery SQL

From Dev

Need to equate more than one property in criteria on joining the tables

From Dev

Do I need to filter all subqueries before joining very large tables for optimization

From Dev

I need help to understand a formula

From Dev

Need help joining incremental data to a fact table in an incremental manor

From Dev

Need help in joining two tables from mysql database for a photography project

From Dev

I need help please

From Dev

I need help in django

From Dev

I need help on awk

From Dev

Need help joining 2 tables on one

From Dev

I need help in the variables in the Void

From Dev

SQL help joining tables

Related Related

HotTag

Archive