Re: SQL question

From: Date: Fri, 08 Dec 2000 23:23:23 +0000
Subject: Re: SQL question
Groups: php.general 
Request: Send a blank email to php-general+get-29423@lists.php.net to get a copy of this message
Chris, What db are you using? In Oracle, you can use enbeded SQL to get the results you are looking for using the following. select cat_name, "User_2_Interested_In" from categories a, ( select cat_id, 'NO' as "User_2_Interested_In" from categories where cat_id not in (select cat_id from user_interest where user_id = 2) union select cat_id, 'YES' as "User_2_Interested_In" from user_interest where user_id = 2 ) b where a.cat_id = b.Cat_id order by 2 desc; Using other tools it may not be possible and specifically, it is not possible in MYSQL. You will have to use cursor logic and roll through a select and drop certain values into variables and do additional selects off those variables. Basically, you will need to create a report. Hope this helps; David Fordham ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ S U M M I T T E C H N O L O G I E S, I N C. http://www.summittech.com dfordham@summittech.com 4500 S Monaco Ste 1827 303.637.4576 Denver, CO 80237 888.833.7360 Toll Free ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Dear list, > > I want to make a query with a column saying yes/no depending on interest of > a user. > > Suppose i have three tables: > > USER (userID, name) > 1 Chris > 2 Harry > 3 Anna > > CATEGORIES (catID, name) > 4 bicycles > 5 windmills > 20 trees > > USER_INTEREST (userID, catID) > 1 4 > 1 5 > > 2 4 > 2 20 > > 3 20 > > > I would like to get this query result: > > CATEGORIE.naam |user_2_is_interested > --------------------------------- > bicycles|yes > windmills|yes > trees|no > > As you see i want every categorie in one row (each once) and the next row > says whether a user is interested. > > So i made this query: > > SELECT DISTINCT CATEGORIE.naam naam, > IF (1=1,"yes","no") user_2_is_interested > FROM categorie , user_cat > > As you see my IF condition is now 1=1. Of course i want to see whether the > current user ($UID) is interested in this specific categorie. > But as soon as i try to adapt the WHERE or the IF i get all sorts of doubles. > Help? > Chris > > > -------------------------------------------------------------------- > -- C.Hayes Droevendaal 35 6708 PB Wageningen the Netherlands -- > -------------------------------------------------------------------- > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.general (#29423) next »