Re: Logicproblem in WHERE statement

From: Date: Wed, 16 Jan 2002 10:41:28 +0000
Subject: Re: Logicproblem in WHERE statement
Groups: php.db 
Request: Send a blank email to php-db+get-15872@lists.php.net to get a copy of this message
=An alternative approach:- > > I am building a user search engine. Now I do not know how to gett > > following: > > > > a mandatory field and a voluntary field > > > > For example I would like to get all female users and those who are from > > canada. > > The results should show all users who are female regardless of nationality > > But it should also show all users from canada. > > > > How would this look like? > > > > SELECT * > > FROM table > > WHERE sex=1 AND country='CA' > > > > This is wrong I know. But how does it work??? > > SELECT * FROM TABLE > WHERE sex = 1 OR country = 'CA'; > > Will select all users who are female as well as all users from Canada. You > may get duplicate records (for people who are female and from Canada) so you > may want to use DISTINCT as well. =If all you want to do is to 'highlight' people from Canada, whilst having a query that gives a worldwide resultset, try: SELECT *, IF( country = 'CA', 'Canuck', 'Normal' ) AS highlight FROM table WHERE sex=1; =Regards, =dn

« previous php.db (#15872) next »