Subject Re: SQL questions
Author Fabrice Aeschbacher
Hi,

> 2- I have 2 tables as follows:
> CREATE TABLE CURRENCIES (
> ID INTEGER,
> CURRENCY_NAME CHAR(30),
> PRIMARY KEY(ID));
>
> CREATE TABLE COUNTRIES (
> ID INTEGER,
> COUNTRY_NAME CHAR(30),
> CURRENCY1 INTEGER,
> CURRENCY2 INTEGER,
> PRIMARY KEY(ID),
> FOREIGN KEY (CURRENCY1) REFERENCES CURRENCIES (ID),
> FOREIGN KEY (CURRENCY2) REFERENCES CURRENCIES (ID));
>
> What's the correct SQL SELECT statement that will give me a list of
> countries with the names of both currencies?

One solution is to use "inline select":

SELECT
CO.COUNTRY_NAME
, (SELECT CURRENCY_NAME FROM CURRENCY CU
WHERE CU.ID = CO.CURRENCY1)
, (SELECT CURRENCY_NAME FROM CURRENCY CU
WHERE CU.ID = CO.CURRENCY2)

FROM
COUNTRY CO

> 3- The CREATE TABLE statement supports an EXTERNAL FILE option. Is
it
> possible to set the external file name from a stored procedure at
run-time?

Not sure, but I don't think so.


HTH,

Fabrice