I have some query that returns this:
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
I don't need repeating data as:
1121 1233 750 128
1233 1121 750 128
It's the same, but with different order of models.
All data stores in one table. There are a lot of PC's which have various models. I need PC's which have the same speed and ram, but I have some problem (described above). Here's my query:
SELECT a.model, b.model, a.speed, a.ram
FROM PC AS a, PC AS b
WHERE a.speed = b.speed AND a.ram = b.ram AND a.model != b.model
ORDER BY a.model DESC, b.model ASC
In your existing query by changing a.model != b.model to a.model > b.model will give you the desired output.
SELECT a.model, b.model, a.speed, a.ram FROM PC AS a, PC AS b
WHERE a.speed = b.speed AND a.ram = b.ram
and a.model > b.model
ORDER BY a.model DESC, b.model ASC
It is recommended to use explicit JOIN for your queries.
You can change your query like following.
SELECT a.model, b.model, a.speed, a.ram
FROM PC AS a
inner join PC AS b on a.speed = b.speed and a.ram = b.ram and a.model > b.model
ORDER BY a.model DESC, b.model ASC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With