sql server - SQL: Struggling to join 3 tables from a many-to-many relationship -


i have 3 tables:

users - username procedures - seriesnum,procnum (composite pkey),description,currentrev usersprocedures - username,seriesnum,procnum,revtrained,leveltrained,datetrained 

how query shows, each user, procedures, , if trained in procedures, values in usersprocedures table (and if they're not trained, values come null because they're not present).

the closest i've got query:

select procedures.seriesnum,procedures.procnum,description,currentrev,revtrained,leveltrained,datetrained,users.username procedures,users left join usersprocedures on usersprocedures.username = users.username 

however doesn't work because values it's pulling usersprocedures table same each procedure, rather being unique each procedure.

-- select whatever columns select p.*, u*, pu.* -- cross join conmbines rows both tables  procedures p  cross join users u -- add exp mix  left join usersprocedures pu      on  pu.username = u.username      , p.seriesnum = pu.seriesnum       , p.procnum = pu.procnum  

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -