sql query [message #305777] |
Wed, 12 March 2008 00:22  |
tannad
Messages: 43 Registered: January 2008 Location: mumbai
|
Member |
|
|
Hi all ..
I have one table as test
CREATE TABLE skill
(skillid number(10),candidateid number(10));
in that the values are
SKILLID CANDIDATEID
-------- -----------
1 6
2 6
1 7
3 8
1 4
2 4
1 5
2 9
1 9
2 22
1 33
2 2
now I want the data which contain the candidate who have the
the skill set id 1 and 2 both;
If the candidate have only one skill id suppose 1 then it will ignore.
data will appeare as
SKILLID CANDIDATEID
-------- -----------
1 6
2 6
1 4
2 4
Means the candidate who have both skill 1and 2 will only show.
Can you tell mi what is the query for this...
Thanks...
|
|
|
|
|
Re: sql query [message #305788 is a reply to message #305777] |
Wed, 12 March 2008 01:00   |
mshrkshl
Messages: 247 Registered: September 2006 Location: New Delhi
|
Senior Member |
|
|
Quote: | Can you post what you tried and where you are facing the problem.
Use :Group by and Having.
|
regards,
|
|
|
|
Re: sql query [message #305811 is a reply to message #305788] |
Wed, 12 March 2008 02:00   |
tannad
Messages: 43 Registered: January 2008 Location: mumbai
|
Member |
|
|
Hii
I got the answer by using this query
select candidateid from test
where skillid=1
intersect
select candidateid from test
where skillid=2;
But If my Skillset is multiple as (1,2,3,4,..to 50)
I have to write the intersect for many time for the skillset
can I write any procedure for this where I will give the skillset
id and I will get the candidates who have the all the skill set ?
Tannad
|
|
|
Re: sql query [message #305813 is a reply to message #305811] |
Wed, 12 March 2008 02:09   |
dhananjay
Messages: 635 Registered: March 2002 Location: Mumbai
|
Senior Member |
|
|
@tannad:you have been given clues so try to make use of that.Why do you want to use a PROCEDURE when you can achive the same thing in SQL?
regards,
|
|
|
Re: sql query [message #305821 is a reply to message #305777] |
Wed, 12 March 2008 02:31   |
kecd_deepak
Messages: 52 Registered: December 2007
|
Member |
|
|
Hello,
You use this also..........
But ....i need more optimize solution...............For this
SELECT candidateid,skillid
FROM skill
WHERE candidateid IN ( SELECT candidateid
FROM skill
WHERE skillid IN (1,2)
GROUP BY candidateid
HAVING COUNT(candidateid) > 1 )
|
|
|
|
Re: sql query [message #305871 is a reply to message #305777] |
Wed, 12 March 2008 05:01   |
dr.s.raghunathan
Messages: 540 Registered: February 2008
|
Senior Member |
|
|
hi
i am a newbie. Using the following i achieved the desired
result set.
select candidateid,skillid from skillset where
candidateid in (select candidateid from (
select candidateid,count(skillid) rn from
skillset where skillid in (1,2) group by
candidateid) where rn=2)
how is it?
yours
dr.s.raghunathan
|
|
|
Re: sql query [message #305885 is a reply to message #305777] |
Wed, 12 March 2008 05:26   |
mshrkshl
Messages: 247 Registered: September 2006 Location: New Delhi
|
Senior Member |
|
|
Quote: | Now please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.
|
regards,
|
|
|
|
Re: sql query [message #305906 is a reply to message #305887] |
Wed, 12 March 2008 05:49   |
daniel_india
Messages: 4 Registered: March 2008
|
Junior Member |
|
|
hi,
i tried one of the above solutions which u mentioned.
but, suppose candidateid=22 having skill id=2 as a duplicate record,
then it is returning candiateid 22 also.
eg:
SELECT t1.*
FROM skill t1,
(SELECT skill.candidateid,COUNT(*)
FROM skill
WHERE skillid IN (1,2)
GROUP BY skill.candidateid
HAVING COUNT(*) = 2) t2
WHERE t1.candidateid = t2.candidateid
|
|
|
|
Re: sql query [message #305918 is a reply to message #305871] |
Wed, 12 March 2008 06:05   |
tannad
Messages: 43 Registered: January 2008 Location: mumbai
|
Member |
|
|
This sql whill return only result for candidate 4, and 9
I want the the query such that
I have multple skillsetid from (1 to 50)
If I give the in skillsetid (1 2,3) then the result will giving the candidateid which having there both 1,2,3 skillset..
in this way I can search the candidate who have multiple skillset..
and this skill set I want to give in substitution variable (&)
means only I have to give the skillset id as 1,2 ,3..
then is will give the desire candidate who have all skill set which we are passing..
|
|
|
|
|
Re: sql query [message #305934 is a reply to message #305777] |
Wed, 12 March 2008 06:25   |
brintha
Messages: 28 Registered: August 2007
|
Junior Member |
|
|
hi,
try using this.
select candidateid from
(select candidateid,count(distinct skillid) cnt
from skill where
skillid in ('1','2')
group by candidateid)
where cnt=2
here you can change the cnt value to see if the candidate has all the skillids that are in 'in' clause and distinct will eliminate the duplicate skillid.
regards,
brintha
|
|
|
|
|
|
|
|