Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data by matching same table in Mysql
    primarykey
    data
    text
    <p>I have following table structure in Mysql DB Table: Mytable</p> <pre><code>-------------------------------- | uid | locationid | projectid | -------------------------------- | 2 | 4 | 2 | | 2 | 4 | 2 | | 2 | 3 | 5 | | 2 | 3 | 5 | | 2 | 1 | 2 | | 2 | 1 | 2 | | 2 | 1 | 2 | | 2 | 1 | 1 | | 3 | 1 | 5 | | 3 | 1 | 2 | | 3 | 1 | 1 | | 3 | 1 | 1 | | 7 | 3 | 1 | | 5 | 1 | 5 | | 6 | 4 | 2 | | 5 | 1 | 5 | | 3 | 4 | 1 | | 3 | 3 | 3 | | 7 | 4 | 2 | | 7 | 4 | 3 | </code></pre> <p>Say I passed uid=2 then for uid=2 unique combination of locationid and projectid is this</p> <pre><code>| 2 | 4 | 2 | | 2 | 3 | 5 | | 2 | 1 | 2 | | 2 | 1 | 1 | </code></pre> <p>Now I want all uids with above locationid and projectid combination match. Means result should be</p> <pre><code>| 3 | 1 | 2 | | 3 | 1 | 1 | | 3 | 1 | 1 | | 6 | 4 | 2 | | 7 | 4 | 2 | </code></pre> <p>If I pass uid=3 then result should be</p> <pre><code>| 2 | 1 | 2 | | 2 | 1 | 2 | | 2 | 1 | 2 | | 2 | 1 | 1 | | 5 | 1 | 5 | | 5 | 1 | 5 | </code></pre> <p>For this I used following query but it gives wrong result as locationid and projectid combination is not match properly</p> <pre><code> SELECT a.* FROM Mytable a, Mytable b WHERE a.locationid = b.locationid AND a.projectid = b.projectid AND a.locationid IN (SELECT DISTINCT locationid FROM Mytable WHERE uid=$pmid) AND a.projectid IN(SELECT DISTINCT projectid FROM Mytable WHERE uid=$pmid) AND a.uid !=$pmid </code></pre> <p>Here $pmid is uid value which I passed. What is wrong with my query? Is my query is right? Please help me.</p> <p>Thanks in advance.</p>
    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