| From: | Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com> |
|---|---|
| To: | Devinder K Rajput <Devinder(dot)Rajput(at)ipaper(dot)com> |
| Cc: | PostgreSQL Mailing List <pgsql-novice(at)postgresql(dot)org> |
| Subject: | Re: if statement |
| Date: | 2002-10-22 00:57:18 |
| Message-ID: | 20021022005718.27079.qmail@web80314.mail.yahoo.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
--- Devinder K Rajput <Devinder(dot)Rajput(at)ipaper(dot)com>
wrote:
> Hi,
>
> I am trying to find out how to do an if
> statement/case statement inside a
> select. I am comparing item records to find out
> what is different. Rather
> than writing a query for comparing each field
> separately, I just want to
> tell which field is different by printing the name
> of that field. Thank
> you.
Use the CASE clause, it simulates the if-then-else
statement in SQL.
Try the following:
SELECT a.number,
a.description_1,
a.description_2,
....
....
CASE
WHEN a.description_1 <> b.description_1
THEN
'description_1'
WHEN a.description_2 <> b.description_2
THEN
'description_2'
/* Some more WHEN-THEN statements.... */
END
FROM .....
WHERE .....
regards,
ludwig.
__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joel Rodrigues | 2002-10-22 07:08:50 | Re: Big Picture |
| Previous Message | working4aliving | 2002-10-22 00:36:01 | Re: Big Picture |