clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2042960 fiddles created (16655 in the last week).

create table employee( id varchar(20) primary key, userregionid varchar(20))
 hidden batch(es)


insert into employee values('E-999','12345')
1 rows affected
 hidden batch(es)


insert into employee values('E-888','12345')
1 rows affected
 hidden batch(es)


insert into employee values('Y-8323','2233')
1 rows affected
 hidden batch(es)


select * from employee
ID USERREGIONID
E-999 12345
E-888 12345
Y-8323 2233
 hidden batch(es)


create table userrestriction(userid varchar(20), restrictiongroup varchar(20))
 hidden batch(es)


insert into userrestriction values('E-999','A1')
1 rows affected
 hidden batch(es)


insert into userrestriction values('E-999','C1')
1 rows affected
 hidden batch(es)


insert into userrestriction values('E-888','B1')
1 rows affected
 hidden batch(es)


select * from userrestriction
USERID RESTRICTIONGROUP
E-999 A1
E-999 C1
E-888 B1
 hidden batch(es)


create table restrictions(item varchar(20), restrictiongroup varchar(20), restriction number, interval number)
 hidden batch(es)


insert into restrictions values('Green Balls', 'A1',1,30)
1 rows affected
 hidden batch(es)


insert into restrictions values('Green Balls', 'C1',1,1)
1 rows affected
 hidden batch(es)


insert into restrictions values('Pen', 'C1',1,30)
1 rows affected
 hidden batch(es)


select * from restrictions
ITEM RESTRICTIONGROUP RESTRICTION INTERVAL
Green Balls A1 1 30
Green Balls C1 1 1
Pen C1 1 30
 hidden batch(es)


SELECT employee.id, userrestriction.restrictiongroup, restrictions.item, restrictions.restriction, restrictions.interval FROM employee left outer join userrestriction ON employee.id = userrestriction.userid left outer join restrictions ON userrestriction.restrictiongroup = restrictions.restrictiongroup where employee.userregionid = '12345' GROUP BY userrestriction.userid, employee.id, userrestriction.restrictiongroup, restrictions.item, restrictions.restriction, restrictions.interval, employee.userregionid HAVING Count(userrestriction.restrictiongroup) > 1
ID RESTRICTIONGROUP ITEM RESTRICTION INTERVAL
 hidden batch(es)