I am trying to get user and security group data from two different tables (users & secgroup). However there is no join between the two tables. There is a third table (secbygrp) that allows a one-to-many join from each of the first two tables. For instance:
users.id
secgroup.groupid
secbygrp.id
secbygrp.groupid
users.id >> secbygrp.id
secgroup.groupid >> secbygrp.groupid
How can I go about selecting records from users and their corresponding secgroup records using the secbygrp table as the join?
This is what I have right now and I know why it's wrong, but I just can't wrap my head around how to join the two tables through the third table.
users.id
secgroup.groupid
secbygrp.id
secbygrp.groupid
users.id >> secbygrp.id
secgroup.groupid >> secbygrp.groupid
How can I go about selecting records from users and their corresponding secgroup records using the secbygrp table as the join?
This is what I have right now and I know why it's wrong, but I just can't wrap my head around how to join the two tables through the third table.
Code:
SELECT u.code, u.descrip, sg.code, sg.descrip
FROM users u, securitygroup sg
WHERE u.id in (SELECT id from secbygrp sbg)
and sg.groupid in (SELECT groupid from secbygrp sbg)