dcsimg
Please Help Me <font color=red>SQL QUERY PROBLEM</font>
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sabu_vs
Posted On:   Thursday, June 13, 2002 12:43 AM

Hi I have a table "Profile" that contains name,age and sex fields. I have to select data from this table that match a condition. The normal sql query I use is "select * from Profile where age between 10 and 30" I want to include a criteria in the above query. ie; If any record that has a name field "sabu" ; then I want to check 'if sex=male' and select from the table for eg. name     age     sex ----- --- --- abc1     45     female abc2     20     female sabu       More>>

Hi



I have a table "Profile" that contains name,age and sex fields.

I have to select data from this table that match a condition.



The normal sql query I use is "select * from Profile where age between 10 and 30"



I want to include a criteria in the above query.



ie; If any record that has a name field "sabu" ; then I want to check 'if sex=male'
and select from the table






for eg.


name     age     sex

----- --- ---

abc1     45     female

abc2     20     female

sabu     28     male

sabu     29     female





In the above table the I want to select 3 rows



ie, abc1,abc2,sabu



The 1st and second records are selected because the "name != sabu"

The 3rd record has a name field "sabu" so I have to check if the 'sex=male'.In this case it is true and included in the selection

The 4th record also has a name field "sabu" but the "sex=female" ; so it is excluded.




Could you pls tell me waht is the SQL Query to do this.

Does sub query help to solve this?



thanks for your time


sabu

   <<Less

Re: Please Help Me <font color=red>SQL QUERY PROBLEM</font>

Posted By:   Anonymous  
Posted On:   Thursday, June 13, 2002 10:29 AM

You could try something around MINUS operator.

Following example will work in your demo table, but may not work in actual table. Just a outline to solution, thats all.



Select *

from profiles

MINUS

( select *

from profiles

where name='sabu' AND sex='female'

)





HTH,


Ashok.
About | Sitemap | Contact