tags:

views:

56

answers:

5

My query is:

Table name: employee

id(pk) name    salary
1      prasad  1000
2      prasad  2000
3      gopi    3000
4      gopi    3500
5      seenu   2500
6      nag     1000

I want get only seenu and nag records. Above table column name is not unique.

+1  A: 

Use a WHERE and IN clause here:

SELECT *
FROM employee
WHERE name IN ('seenu', 'nag')
Nick Craver
A: 

From the limitted detail you provided, I can only quess, but lets say

SELECT *
FROM employee
WHERE name IN ('seenu','nag')
astander
+3  A: 

Sounds to me like you want to find only the records that don't have a duplicate (i.e. names which occur only once):

SELECT *
FROM Employee e
WHERE NOT EXISTS(
       SELECT e2.ID
       FROM Employee e2 
       WHERE e2.name = e.name AND e2.ID <> e.ID)
AdaTheDev
+1  A: 

It depends entirely on the conditions you're trying to match against. If you want those specific names, use:

select * from employee where name in ('seenu','nag');

If you want IDs above 4:

select * from employee where id > 4;

If you want non-duplicate names:

select * from employee group by name having count(*) = 1;

As you can see, there are numerous possibilities, depending on your actual needs (which should be fleshed out a little more).

paxdiablo
+1  A: 
SELECT name 
FROM employee 
GROUP by name
HAVING COUNT(*) = 1;
Fred