Sto utilizzando Mysql e sto avendo difficoltà a cercare di ottenere i risultati da una query SELECT. Sto avendo 3 tavoli. Prime sezioni della tabella, membri della sezione della seconda tabella e stato membro della sezione della terza tabella (i dati in questa tabella sono statici).Più tabelle join con clausola WHERE
select * from Sections;
| section_id | title | description | section_ownerid |
-------------------------------------------------------
| 1 | title1 | desc1 | 100 |
| 2 | title2 | desc2 | 100 |
| 3 | title3 | desc3 | 100 |
| 4 | title4 | desc4 | 100 |
| 5 | title5 | desc5 | 100 |
| 6 | title6 | desc6 | 100 |
select * from SectionMembers;
| SectionMembers_id | section_id | status_code | memberid |
------------------------------------------------------------
| 1 | 1 | 10 | 200 |
| 2 | 1 | 20 | 300 |
| 3 | 2 | 30 | 200 |
| 4 | 2 | 10 | 300 |
| 5 | 3 | 30 | 200 |
| 6 | 4 | 20 | 200 |
select * from MemberStatus;
| MemberStatus_id | status_code | status |
---------------------------------------------------
| 1 | 10 | PENDINGMEMBER |
| 2 | 20 | ACTIVEMEMBER |
| 3 | 30 | MEMBERREJECTED |
ho usato si unisce per ottenere risultati come
select distinct(a.section_id) as id,
a.title,
a.description,
c.status
from Sections a
left join SectionMembers b on a.section_id = b.section_id
inner join MemberStatus c on b.status_code = c.status_code
where (a.section_ownerid = 100 and b.memberid = 200)
or (a.section_ownerid = 100);
Ma io non sto ottenendo risultato corretto. Voglio risultati come illustrato di seguito:
| section_id | title | description | status |
------------------------------------------------------
| 1 | title1 | desc1 | PENDINGMEMBER |
| 2 | title2 | desc2 | ACTIVEMEMBER |
| 3 | title3 | desc3 | MEMBERREJECTED |
| 4 | title4 | desc4 | ACTIVEMEMBER |
| 5 | title5 | desc5 | NULL |
| 6 | title6 | desc6 | NULL |
questo ha funzionato perfettamente. Grazie bluefeet. – Bhargav
@BhargavBonu sei il benvenuto! :) – Taryn
Questo ha aiutato! Grazie !! 1 – normalUser