Обсуждение: Select by priority again
Sorry about this, but I don't quite get previous postings regarding select by prioriry. I have the same question with my sql. I want to be able to select cell_phone if there is one in the table; otherwise, I will select work_phone. table ------ id, name, address, cell_phone, work_phone,... and I tried using "case when...end" but nope, it's not gonna work. Help is needed. Thanks. - Bernie
Вложения
[Note: PHP mailing list removed from Cc as this is strictly a PostgreSQL question I think.]
Thus spake Bernie Huang
> Sorry about this, but I don't quite get previous postings regarding
> select by prioriry.
>
> I have the same question with my sql. I want to be able to select
> cell_phone if there is one in the table; otherwise, I will select
> work_phone.
>
> table
> ------
> id, name, address, cell_phone, work_phone,...
>
> and I tried using "case when...end" but nope, it's not gonna work. Help
> is needed. Thanks.
Exactly what was the SQL statement and which version of PostgreSQL? I
do this in a view and it works.
SELECT CASE WHEN login IS NULL THEN uid::text ELSE login END AS login FROM account;
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
"D'Arcy J.M. Cain" wrote:
> [Note: PHP mailing list removed from Cc as this is strictly a
> PostgreSQL question I think.]
>
> Thus spake Bernie Huang
> > Sorry about this, but I don't quite get previous postings regarding
> > select by prioriry.
> >
> > I have the same question with my sql. I want to be able to select
> > cell_phone if there is one in the table; otherwise, I will select
> > work_phone.
> >
> > table
> > ------
> > id, name, address, cell_phone, work_phone,...
> >
> > and I tried using "case when...end" but nope, it's not gonna work. Help
> > is needed. Thanks.
>
> Exactly what was the SQL statement and which version of PostgreSQL? I
> do this in a view and it works.
>
> SELECT CASE WHEN login IS NULL THEN uid::text ELSE login END AS login
> FROM account;
>
> --
> D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
> http://www.druid.net/darcy/ | and a sheep voting on
> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
hi, thanks for the help. I will avoid to CC to the wrong list.
- Bernie