You are here: Re: [PHP] SQL ternary thing « PHP « IT news, forums, messages
Re: [PHP] SQL ternary thing

Posted by Philip Hallstrom on 04/07/05 00:23

CASE should do it...

http://www.postgresql.org/docs/7.4/interactive/functions-conditional.html

Say's it's SQL compliant so it should be fine for other db's as well...
something like:

SELECT name,
CASE WHEN value=1 THEN name_if_true
ELSE name_if_false
END
FROM thing;

Might need to throw an "AS colname" in there depending on how you fetch it
with PHP...

On Wed, 6 Apr 2005, Rory Browne wrote:

> Hi
>
> I appreciate this is an SQL issue, more than a PHP issue, but since it
> isn't a DB specific issue, and I'm planning on using it with PHP(and
> I'm not subscribed to any SQL lists), I thought I'd post it here.
>
> I have a table a bit like the following:
>
> create table thing (name char(10), value boolean, name_if_true
> char(10), name_if_false(10))
>
> Basicly what will be modified will be the value field. name_if_true,
> and name_if_false are static(and will in practice be in a different
> table). The table may look a bit like the following:
>
> | Accept | 0 | Yes | No |
> | Gender | 1 | Female | Male
> | State | 0 | Broken |fixed
>
> Can anyone suggest a query that will return:
>
> | Accept | No
> | Gender | Female
> | State | fixed
>
> Preferably in a db independent manner.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация