my tables are:
allowed(resourceid, personid) person(personid, email) i want print out whether person has right access resource, lets resourceid = 2. result should be:
personright(personid, email, resourceid) and resourceid should null if person not allowed access resource 2. if person allowed access 2, resourceid should 2.
so expect everytime query executed whole user list printed out.
i had working solution using subquery, want join.
select person.personid, person.email, allowed.resourceid person right join allowed on(person.personid = allowed.personid) (allowed.resourceid null or allowed.resourceid = 2); why not work?
based on description of problem - should left join here, not right join.
select person.personid, person.email, allowed.resourceid person left join allowed on person.personid = allowed.personid , allowed.resourceid = 2 also note i've moved allowed.resourceid = 2 condition where clause join condition. if there no matching records in allowed table having resourceid = 2 , personid equals appropriate personid person table - null allowed.resourceid required.
Comments
Post a Comment