I am new to SQL programming and I am having the following problem.
I have 3 tables :
- tblMaschine (id PK, type as char(5))
- tblUse (id PK, typeOfUse varchar(255))
- tblmaschineUse (mid, uid both PK and each as FK to the above tables)
This is a many to many relationship. I have inserted this data in the tables:
tblmaschine
id|type
--+-----
1 |M1
2 |M2
3 |M3
tbluse
id|typeOfUse
--+---------
1 |U1
2 |U2
and
tblmaschineUse
id|type
--+-----
1 |1
1 |2
2 |1
3 |2
I want to query to find the maschine
type from tblmaschine
which has the both types of use in table maschineUse
.
I am using this query but it returns nothing:
select m.type
from tblmaschine as m
inner join tblmaschineUse as mu on m.id = mu.mid
inner join use as u on u.id = mu.uid
where u.typeOfUse = 'U1' and u.typeOfUse = 'U2';
What am I doing wrong?