[development] SQL Query Doubt

Austin Einter austin.einter at gmail.com
Sat Apr 16 11:53:48 UTC 2011


Hi Robbie,
Thanks for reply.

This will work , but it will give employess who has either PHP or Java skill
or both.

What I wanted is , result should give employess having both PHP and Java
skill.

I figured it out, the syntax should be as below.

SELECT EmployeeID
FROM `table`
WHERE `skill` IN ('PHP','Java')
GROUP BY EmployeeID
HAVING COUNT(*) = 2

This query's result gives employee ids who has both PHP and Java skills.

The link
http://stackoverflow.com/questions/4049650/what-sql-query-for-multiple-rows-with-one-value-the-same-in-each
was
really helpful.

Thanks a lot for helping me.

Regards
Austin.


On Sat, Apr 16, 2011 at 5:17 PM, Robbie The Geek <robbiethegeek at gmail.com>wrote:

>
> SELECT EmployeeID FROM {tablename} WHERE Skill IN ( 'PHP', 'Java');
>
>
> ----- Reply message -----
> From: "Austin Einter" <austin.einter at gmail.com>
> To: <development at drupal.org>
> Cc: "Jason Flatt" <drupal at oadaeh.net>
> Subject: [development] SQL Query Doubt
> Date: Sat, Apr 16, 2011 7:33 am
>
>
> Hi
> Thanks for reply.
>
> I  have tried SELECT EmployeeID FROM {tablename} WHERE Skill = 'PHP' AND
> Skill = 'Java';  .  It does not work.
> Probably in SQL in same row of table both values are not matching.
> Regards,
> Austin
> On Sat, Apr 16, 2011 at 4:54 PM, Jason Flatt <drupal at oadaeh.net> wrote:
>
>>  On Sat, 16 Apr 2011 16:09:59 +0530
>> Austin Einter <austin.einter at gmail.com> wrote:
>>
>> > Hi All
>> >
>> > Lets say I have one table in below format.
>> >
>> > EmployeeID.............. Skill
>> > ------------------------------------------------------
>> > 1...............................PHP
>> > 1...............................SQL
>> > 1...............................Java
>> > 1................................VoIP
>> >
>> > 2................................Shell Scripting
>> > 2................................PHP
>> > 2................................Java
>> >
>> > 3............................... C++
>> > 3................................C
>> > 3.................................Pearl
>> >
>> > I wan to do a SQL query for employess who MUST have skill PHP and Java.
>> > As per above table, the query result should show Employee 1 and 2.
>> >
>> > Now what should be the corresponding SQL query for it.
>>
>> SELECT EmployeeID FROM {tablename} WHERE Skill = 'PHP' AND Skill = 'Java';
>>
>> This might help a bit:
>> http://dev.mysql.com/doc/refman/5.1/en/sql-syntax.html
>>
>>
>> --
>> Jason Flatt
>> Custom Website development solutions: http://www.oadaeh.net/
>> Father of seven: http://www.flattfamily.com/ (Joseph, 18; Cramer, 16;
>> Travis,
>> 14; Angela; Harry, 10; William, 5; and Dolly, 2) Linux user:
>> http://www.ubuntu.org/ Android user: http://www.android.com/
>> Drupal fanatic: http://drupal.org/
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110416/e2d00366/attachment-0001.html 


More information about the development mailing list