Re: Query with IF acting wierd.

2004-03-12 Thread Michael Stassen
Mike Johnson wrote: From: Mike Johnson SELECT main.id, IF(main.type,categories.name,items.name), IF(main.type,"cat","item") AS type FROM main, IF(main.type,items,categories) WHERE IF(main.type,categories.id,items.id)=main.id; Oh, my mistake. I just realized I reversed items and categories in

RE: Query with IF acting wierd.

2004-03-11 Thread Mike Johnson
From: Mike Johnson > SELECT main.id, > IF(main.type,categories.name,items.name), > IF(main.type,"cat","item") AS type > FROM main, IF(main.type,items,categories) WHERE > IF(main.type,categories.id,items.id)=main.id; Oh, my mistake. I just realized I reversed items and categories in the IF c

RE: Query with IF acting wierd.

2004-03-11 Thread Mike Johnson
From: Amir Hardon [mailto:[EMAIL PROTECTED] > I have 3 tables: > > main(id int, type tinyint(1)) > categories(id int, name varchar) > items(id int, name varchar) > > I want to select the id and name. > If type is 1 then I want to select the name from categories, > if type is 0 I want to select t

Re: Query with IF acting wierd.

2004-03-11 Thread Hans van Dalen
Amir, I don't know your table content but if you join two tables eg : table1(id, desc) and table2(id, refid, desc) wich containts: table1: 1 test1 2 test2 table2: 1 1 testbla 2 1 testbla and you select: select id from table1 where table1.id = table2.refid you got two rows (because if you show *

Re: Query with IF acting wierd.

2004-03-11 Thread Amir Hardon
Thanks, but this is just a nicer way to apply my second solution, I'm looking for a more efficient solution (and if someone can than for an explanation - why are the results getting duplicated?) -Amir. On Thursday 11 March 2004 15:40, Hans van Dalen wrote: > SELECT distinct main.id, etc.

Re: Query with IF acting wierd.

2004-03-11 Thread Hans van Dalen
SELECT distinct main.id, etc. etc. At 14:37 11-3-04, you wrote: I have 3 tables: main(id int, type tinyint(1)) categories(id int, name varchar) items(id int, name varchar) I want to select the id and name. If type is 1 then I want to select the name from categories, if type is 0 I want to select

Query with IF acting wierd.

2004-03-11 Thread Amir Hardon
I have 3 tables: main(id int, type tinyint(1)) categories(id int, name varchar) items(id int, name varchar) I want to select the id and name. If type is 1 then I want to select the name from categories, if type is 0 I want to select the name from items, here is the query I'm trying to use: SELE