Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying multiple tables in database
    primarykey
    data
    text
    <p>I have a database with these tables and columns:</p> <h3>Person</h3> <pre><code>firstname lastname peid </code></pre> <h3>Buyer</h3> <pre><code>peid </code></pre> <h3>Offer</h3> <pre><code>peid pno </code></pre> <p>I am trying to select names (buyer 1 and buyer 2) that have the same pno and different peid.</p> <pre><code>FIRSTNAME LASTNAME PEID PNO ------------------------------------------- Robert Young 0 18 Stephen Davison 2 32 Tony Nguyen 16 28 Lily Roy 32 14 Aaron Naidoo 50 51 Adam Jordan 64 32 Arun Isaacson 68 27 Charles Murphy 84 23 Adam Peter 94 27 </code></pre> <p>What I want is to select two buyers that have the same pno and different peid and the pno that they have in common. For example: </p> <p>Adam Jordan and Stephen Davison have 32 in common. Adam Peter and Arun Isaacson have 27 in common. I'm trying to select them. The above table is the result of one of my queries, not the original table.</p> <hr> <p>From a comment:</p> <blockquote> <p>This is what I have done so far</p> </blockquote> <pre><code>select A.firstname || ' ' || A.lastname as Buyer1, B.firstname || ' ' || B.lastname as Buyer2 from person A, person B, buyer One, buyer Two where A.peid = One.peid and B.peid = Two.peid and (select off.pno from offer off where off.peid = One.peid) = (select off.pno from offer off where off.peid = Two.peid) and (select off.peid from offer off where off.peid = One.peid) &lt;&gt; (select off.peid from offer off where off.peid = Two.peid) group by A.firstname || ' ' || A.lastname, B.firstname || ' ' || B.lastname; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload