sql - Query relations within the same table -


I have a table of entities , which relate to multiple relationships from each other You can keep the second, using the junction table. At first glance, the design may look faulty and suggests a separate table for each type of unit. The thing is, the institutions are normal, and fully user-defined. They can be completely linked to the ad hoc and each unit can have unlimited connections. Here is a simple example of my tables:

  institutions ------------ unit | ID | Type ------------------- Events | 1 | Request String | 2 | Activity Dinner | 3 | Activity Angela | 4 | Person enders | 5 | Person Michael | 6 | Person junction ---------------- Left | Correct ---------------- 1 | 2 / Connect Request - & gt; Stall 2 4 / Connect Stall - & gt; Angela 1 | 3 / Connect Request - & gt; Dinner 3 5 // Connect Dinner - & gt; Enders 3 | 6 // Connect Dinner - & gt; Michael   

For my question now:

I want to inquire from the perspective of various institutions. It is said that I would like to see request and see what they have actions , and any person participate in every activity. I would like to get a result by:

  request | Activity | Person ----------------------------- Event | Stole | Angela | Dinner Enders | Michael   

I also see, for example, to flip the coin and see Individuals and what they request will be present Like:

  person | Request ----------------- Angela | Event Enders | Event Michael | Event   

How can I write a question to get such results, and is it possible with the existing structure? I've spent more time on googling and testing with no luck, and I'm very grateful for any help.

how do you do this

  SELECT e1.Entity request, E2.Entity activity, e3.Nets: Junctions j1 JOIN Junctions j2 ON j1 'Wright` = J2. Left 'Joint entities E1 on J1' left '= E1 INDTI E2 ON J1 'Right' = E2. Indits atees E3 on J2 'Right' = e 3. id;   

SELECT j1 'Left' request, J1 Right 'activity, J.2' Write 'Joint Junkies J2 On J1' Right '= j 2.' Left '; To change

and then id s, as you can see, every entered in unit Once for .

But, still, I still think this architecture is awful, and it needs to be redesigned.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -