Subject Re: Need Good Advise for the SELECT query
Author Svein Erling Tysvær
If you're using Firebird 1.5, you could use

SELECT C.COUNTRY_CODE, C.COUNTRY_NAME, (CASE WHEN EXISTS(
SELECT * FROM TABLE_ONE OT WHERE OT.COUNTRY_CODE = C.COUNTRY_CODE)
OR EXISTS(
SELECT * FROM ANOTHER_TABLE AT WHERE AT.COUNTRY_CODE = C.COUNTRY_CODE)
THEN 'No!'
ELSE 'Yes'
END) AS DELETABLE
FROM COUNTRIES C
ORDER BY C.COUNTRY_NAME

HTH,
Set

--- In firebird-support@yahoogroups.com, "william_yuwei" wrote:
> Hi, All
>
> The following query is very simple:
>
> SELECT COUNTRY_CODE, COUNTRY_NAME FROM COUNTRIES
> ORDER BY COUNTRY_NAME
>
> However, I need to add a extra field, DELETABLE, the field which
> indicate if the country record has been used/referenced by records
> in other tables or not, so to use this field to show a state on the
> screen(Grids) visually. I have a lot of SELECT queries which want to
> do the same way. Is there any good way and how to fetch it?
>
> Thanks
>
> William