Query to create higher or equal matched values (1 Viewer)

jaryszek

Registered User.
Local time
Yesterday, 22:43
Joined
Aug 25, 2016
Messages
756
Hi Guys,

i have table like here:



So KeyName and DiskSize corresponding.

And what i want is to get this table:

So for keyName P6-64-Premium_SSD i have 3 keyNames which DiskSizes are bigger or equal: P6-64-Premium_SSD, P20-512-Premium_SSD, P30-1024-Premium_SSD.

For P20-512-Premium_SSD we have P20-512-Premium_SSD (equal) and higher value is P30-1024-Premium_SSD.

For P30-1024-Premium_SSD we have only equal value P30-1024-Premium_SSD.

Database sample in attachment,

How can i write query to achive this?
Please help,
Jacek
 

Attachments

  • Screenshot_39.png
    Screenshot_39.png
    30.7 KB · Views: 87
  • Screenshot_40.png
    Screenshot_40.png
    87.8 KB · Views: 97
  • Database19.accdb
    420 KB · Views: 38

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:43
Joined
Oct 29, 2018
Messages
21,467
Hi. I’m already in bed but try looking into non-equi join queries. See you in the morning.
 

jaryszek

Registered User.
Local time
Yesterday, 22:43
Joined
Aug 25, 2016
Messages
756
ok thank you,

i tried with:

Code:
SELECT TableSource.KeyName, TableSource_1.KeyName
FROM TableSource, TableSource AS TableSource_1
WHERE (([TableSource_1].[DiskSize]>[TableSource].[DiskSize]));

but it failed.



Jacek
 

Attachments

  • Screenshot_41.png
    Screenshot_41.png
    49.9 KB · Views: 73
  • Database19.accdb
    420 KB · Views: 39

isladogs

MVP / VIP
Local time
Today, 06:43
Joined
Jan 14, 2017
Messages
18,216
Try this
Code:
SELECT TableSource.KeyName, TableSource_1.KeyName AS HigherKeySizes
FROM TableSource, TableSource AS TableSource_1
WHERE (((TableSource.DiskSize)>=[TableSource_1].[disksize]))
ORDER BY TableSource.KeyName DESC;
 

jaryszek

Registered User.
Local time
Yesterday, 22:43
Joined
Aug 25, 2016
Messages
756
o wow thank you very much!

Working like a charm!
Jacek
 

isladogs

MVP / VIP
Local time
Today, 06:43
Joined
Jan 14, 2017
Messages
18,216
You're welcome.
Here's another method but it can only be used in SQL view due to the non-equal join

Code:
SELECT TableSource.KeyName, TableSource_1.KeyName AS HigherKeySizes
FROM TableSource AS TableSource_1 INNER JOIN TableSource ON TableSource_1.DiskSize >= TableSource.DiskSize
ORDER BY TableSource.KeyName DESC;

BTW did you try out the approach I outlined recently about deleting specific duplicates?
 

jaryszek

Registered User.
Local time
Yesterday, 22:43
Joined
Aug 25, 2016
Messages
756
hi Colin,

thanks !

Sorry my tasks changed and i didnt have time for it yet :( I will investigate.

Best,
Jacek
 

Users who are viewing this thread

Top Bottom