Subject Re: [ib-support] Rationalise SQL Statement
Author Svein Erling Tysvaer
At 11:48 10.06.2003 +0000, you wrote:
>Select (select 'T' from databox_users u where u.dbox_id = a.dbox_id
>and u.user_id = 'AAVUR0000000001') as selected,
>(select valid_from from databox_users u where u.dbox_id = a.dbox_id
>and u.user_id = 'AAVUR0000000001') as valid_from,
>(select valid_to from databox_users u where u.dbox_id = a.dbox_id
>and u.user_id = 'AAVUR0000000001') as valid_to, a.dbox_id, a.title
>from databox a where a.max_users is not null
>
>is there any way it can be rewritten to avoid three seperate
>subselects?

Well, at least most of it can be rewritten:

SELECT <all-you-want-to-select>
FROM databox a
LEFT JOIN databox_users u ON u.dbox_id = a.dbox_id and u.user_id =
'AAVUR0000000001'
WHERE a.max_users is not null

You'd probably need a subselect for your 'selected' column, though, I
cannot see how else to include 'T' only for those columns that match
databox_users (I'm not saying that it is impossible, just that I cannot see
how to do it).

HTH,
Set