Reputation: 23
I searched before asking my question:
I have two tables.
Table info:
no | name
1 | david
2 | kang
Table info_kill:
no | staffno | skillno
------------------------
1 | 1 | 1
2 | 2 | 1
3 | 2 | 2
4 | 2 | 3
staffno
in info_skill
table and no
in info
table is foreign key.
I want to get:
name
contains 'ka'skillno
1, 2, 3.so, this is my sql,
SELECT a.NAME
FROM (SELECT no,
NAME
FROM info
WHERE NAME LIKE '%ka%') AS a
INNER JOIN info_skill AS b
ON a.no = b.staffno
INNER JOIN info_skill AS c
ON a.no = c.staffno
INNER JOIN info_skill AS d
ON a.no = d.staffno
WHERE b.skillno = '1'
AND c.skillno = '2'
AND d.skillno = '3'
what I wonder is this part.
INNER JOIN info_skill AS b
ON a.no = b.staffno
INNER JOIN info_skill AS c
ON a.no = c.staffno
INNER JOIN info_skill AS d
ON a.no = d.staffno
WHERE b.skillno = '1'
AND c.skillno = '2'
AND d.skillno = '3'
Is there any other way?
Upvotes: 1
Views: 67
Reputation: 204766
select a.name
from info a
inner join info_skill as b on a.no = b.staffno
where b.skillno in (1,2,3)
and name like '%ka%'
group by a.name
having count(distinct b.skillno) = 3
Upvotes: 1
Reputation:
Try this:
SELECT I.name
FROM info I
JOIN info_skill S
ON I.no = S.staffno
WHERE I.name LIKE'%ka%" AND
S.skillno=1 OR
S.skillno=2 OR
S.skillno=3
This means:
LIKE %ka%
If this is not what you need exactly, then please make your question more clear by explaining what you are looking for exactly.
Upvotes: 2