Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get all TITLES's from one table associated with any RANK of a given ID from another

I think I’ve been looking at this too long and have massively overcomplicated it.

I have two tables, TITLES and RANKS. I want to get all TITLES‘s which share any RANK‘s associated to a given ID, tables and expected output below:

+------+------+
|ID    |TITLE |
+------+------+
|1     |A     |
+------+------+
|2     |B     |
+------+------+
|3     |C     |
+------+------+
|4     |D     |
+------+------+
|5     |E     |
+------+------+

+------+------+------+
|USERID|ID    |RANK  |
+------+------+------+
|1     |1     |4     |
+------+------+------+
|2     |2     |2     |
+------+------+------+
|3     |2     |4     |
+------+------+------+
|4     |3     |2     |
+------+------+------+
|5     |3     |5     | 
+------+------+------+

Expected output querying on ID 2 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

+------+
|ID    |
+------+
|A     |
+------+
|B     |
+------+
|C     |
+------+

>Solution :

It sounds like you are asking for just:

select distinct t1.TITLE
from table2 t2id
join table2 t2rank on t2rank.rank=t2id.rank
join table1 on t1.ID=t2rank.ID
where t2id.ID=2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading