Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.29/5 (5 votes)
See more:
id Generated
=========================
1 N
1 N
1 Y
2 Y
2 Y
3 N
3 N
3 N
4 N
5 Y



from the above table i need only that id which is having 'N' for all its rows.

i tried by
select distinct id from table where id not in (select distinct id from table where generated='Y')

table is having so many records, when i run my query its gives error that temp is out of memory(dnt remember exact words)

Could you please provide me some other way to to achieve the output?
Posted
Comments
Schatak 17-Oct-14 1:26am    
You want distinct record for this?

SQL
SELECT DISTINCT
    id
FROM
    your_table
WHERE
    col = 'N'
EXCEPT
SELECT
DISTINCT
    id
FROM
    your_table
WHERE
    col = 'y'
 
Share this answer
 
Hi,

Check this...

SQL
select * from your_table where id not in (select id from your_table where generated='Y' )



Hope this will help you.

Cheers
 
Share this answer
 
Comments
Sanchayeeta 17-Oct-14 1:41am    
My vote 5
Magic Wonder 17-Oct-14 1:42am    
thnx.
princedesai 17-Oct-14 1:43am    
I have written the same query above in my question... this is not working bcz there are lot many data
Magic Wonder 17-Oct-14 2:07am    
How many records are there in your table?
Try this

SQL
select * from #temp t1 where Generated='N'
and not exists
(select ID from #temp t2 where Generated='Y' and t1.Id=T2.Id)



and do apply distinct on selection afterwords so that your query processing does not take much time.
 
Share this answer
 
select * from yourtablename where Generatedlike('%N%')
or
select * from yourtablename where Generated='N'
or
select Distinct id from yourtablename where Generated='N'

you can try any one query from above ,You may get required selection ,
I Think it will be solve you are problem

Regards

K Ramesh
 
Share this answer
 
Comments
CHill60 18-Oct-14 7:43am    
This would include id=1 which also has a Y row
Use the Query as :

select distinct id from (select id from tablename where code <> 'Y');
 
Share this answer
 
this is the simplest solution . . . .
select Distinct id from yourtablename where Generated='N'
 
Share this answer
 
Comments
CHill60 18-Oct-14 7:42am    
This would include id=1 which also has a Y row
select distinct id from table where Generated='N';
 
Share this answer
 
Comments
Sanchayeeta 17-Oct-14 1:21am    
This will result all IDs whichever having at least one Generated='N'
princedesai 17-Oct-14 1:41am    
I need only that values where for that specific id there is no Y in any column.

for eg. 1 is having one Y in 3rd row.. so it should be neglected.

according to the above table only 3 and 4 should be returned..

Sanchayeeta 17-Oct-14 1:45am    
yes, and this will not return id which is having 'N' for all its rows.
princedesai 17-Oct-14 1:48am    
Correct sanchayeeta..
select distinct id from table where Generated like 'N';
 
Share this answer
 
Comments
CHill60 18-Oct-14 7:42am    
This would include id=1 which also has a Y row

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900