CSgirl - 9 months ago 135

SQL Question

I have been asked this question for an assignment:

Find those pairs of PC models that have both the same speed and RAM. A pair should be listed

only once e.g. if

`(I,j)`

`(j,i).`

Result:

`PC1.model PC2.model`

1004 1012

The following code that I wrote:

`SELECT distinct PC1.model, PC2.model`

FROM PC PC1,PC PC2

WHERE PC1.model < PC2.model and PC1.speed = PC2.speed and PC1.ram = PC2.ram;

Gives me the answer:

`MODEL MODEL`

1004 1012

However my the two column names were supposed to be

`PC1.model and PC2.model`

I tried changing my code to the code below

`SELECT distinct PC1.model as 'PC1.model', PC2.model as 'PC2.model'`

FROM PC PC1,PC PC2

WHERE PC1.model < PC2.model and PC1.speed = PC2.speed and PC1.ram = PC2.ram;

, but I keep getting an error:

Error at Command Line : 1 Column : 30

Error report -

SQL Error: ORA-00923: FROM keyword not found where expected

00923. 00000 - "FROM keyword not found where expected"

*Cause:

*Action:

I've tried everything I can, I just want to rename my columns but I can't seem to find a way. Any help would be appreciated.

Answer Source

Try like this:

```
SELECT distinct PC1.model as "PC1.model", PC2.model as "PC2.model"
FROM PC PC1,PC PC2
WHERE PC1.model < PC2.model and PC1.speed = PC2.speed and PC1.ram = PC2.ram;
```