I am trying to solve a sql exercise.
Here is the circuit
PC
code int
model varchar(50)
speed smallint
ram smallint
hd real
cd varchar(10)
price money
Problem:
Find pairs of PC models that have similar speeds and RAM. As a result, each resulting pair is shown only once, i.e. (i, j), but not (j, i).
I wrote a query, but it displays (i, j) along with (j, i).
My request:
select t1.model,t2.model,t1.speed,t1.ram from pc t1 , pc t2
where t1.speed = t2.speed and t1.ram = t2.ram and t1.model != t2.model
Output:
model model speed ram
1121 1233 750 128
1232 1233 500 64
1232 1260 500 32
1233 1121 750 128
1233 1232 500 64
1260 1232 500 32
Required Conclusion:
model model speed ram
1233 1121 750 128
1233 1232 500 64
1260 1232 500 32
So how do I avoid (j, i) in my output?
Thank.
source
share