last day (14 days later) » 

8:06 PM
1
A: MySQL to search using joins

scaisEdgeYou could use an having clause on count of s.name select cs.cid from candskill cs inner join skills s on (cs.sid = s.sid and s.name in ( 'oracle' , 'testing')) group by cs.cid having count(distinct(s.name)) = 2 for 1 or 2 select cs.cid from candskill cs inner join skil...

 
@JuanCarlosOropeza . correct .. to me seems that tha OP is looking for both ..
 
Well @scais Edge - I executed your query and it took around 64 sec to complete.
 
YOu have asket for the result not for performance ..,then if my answer is right ..mean that response to yiu question .. (i don't know how many rows you have .. if you have index or not .. and so on .. )
 
I am looking for both OR , AND combination. My user will want candidates for 1. oracle and testing both, 2. either oracle or testing. So based on that I will have to generate query based on what user is searching for. So, I want a solution where all the things can be handled via minimum changes in query string.
Yeah yeah @scais Edge. I agree, your solution works. I wasn't criticizing. Was just letting you know that its better than 124 sec which was my query.
 
@NalinAgrawal answer udpated for 1 and 2 too as suggest by JuanCarlosOropeza
How many rows you have in both tables?
 
8:06 PM
Around more than 250,000 in my local instance. Production will have more than 500,000 and growing.
 
you have index on skill (name, id) (in reverse order .. ? could an index of this type improve your performance
 
Just checked. Unfortunately no.
 
Is just a suggestion .. then hope my answer is useful al least ..
 
:) Yep. Thanks.
 
have got some others questions?
 
8:07 PM
One more question. Isn't performance of in worse than equality check? I want to know your thoughts on this.
so instead of in(a, b) can we do something like - s.name = a or s.name = b and manage somehow?
 
If you use or the equility work as the in clause ..
 
what about and?
oh okay.
 
explain better you last comment .. i don't understand well
 
okay. So "in" is equivalent to "or". Right? But in the cases where I have to show my user the candidates who have both 'oracle' and 'testing', then won't ot be better to use "and" and avoid "in"?
Just asking, because your answer fits perfectly because I will have to do minimum changes in my php code to achieve, but I am asking to increase my knowledge.
 
for performance is better the in clause that repeat or condition .. you can take a look at the mysql doc there is a chapeter well done for performance .. is useful
 
8:12 PM
okay, Thanks sacisEdge, for your help. I appreciate it.
 
Ok thanks you .. have a good day ..
 

last day (14 days later) »