• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Need Help For Query

Joined
Jan 2, 2008
Messages
3,296 (0.55/day)
System Name Thakk
Processor i7 6700k @ 4.5Ghz
Motherboard Gigabyte G1 Z170N ITX
Cooling H55 AIO
Memory 32GB DDR4 3100 c16
Video Card(s) Zotac RTX3080 Trinity
Storage Corsair Force GT 120GB SSD / Intel 250GB SSD / Samsung Pro 512 SSD / 3TB Seagate SV32
Display(s) Acer Predator X34 100hz IPS Gsync / HTC Vive
Case QBX
Audio Device(s) Realtek ALC1150 > Creative Gigaworks T40 > AKG Q701
Power Supply Corsair SF600
Mouse Logitech G900
Keyboard Ducky Shine TKL MX Blue + Vortex PBT Doubleshots
Software Windows 10 64bit
Benchmark Scores http://www.3dmark.com/fs/12108888
MS Sql Query that is ^^..

I cant seem to describe the problem in google..

basically it looks something like this:


Then I just want my result to be like this:



Basically, I want to get only the Suppl With the latest Create date (the maximum date for each suppl.. In this case, suppl 13 has 11:28, suppl 20 has 11:27 etc.. it doesnt include the other Suppl.

Basicall some kind of a select distinct on the suppl, but at the same time, takes the Create in matter as well..

Ive been thinking for hours on this lol. Just want to ask if its possible in sql, otherwise, I'll do in through the app.. which is kind of expensive since instantiating connection is not quite friendly.. there can be a few hundreds of Suppl numbers that might show..
 
Last edited:

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,051 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
Joined
Jan 2, 2008
Messages
3,296 (0.55/day)
System Name Thakk
Processor i7 6700k @ 4.5Ghz
Motherboard Gigabyte G1 Z170N ITX
Cooling H55 AIO
Memory 32GB DDR4 3100 c16
Video Card(s) Zotac RTX3080 Trinity
Storage Corsair Force GT 120GB SSD / Intel 250GB SSD / Samsung Pro 512 SSD / 3TB Seagate SV32
Display(s) Acer Predator X34 100hz IPS Gsync / HTC Vive
Case QBX
Audio Device(s) Realtek ALC1150 > Creative Gigaworks T40 > AKG Q701
Power Supply Corsair SF600
Mouse Logitech G900
Keyboard Ducky Shine TKL MX Blue + Vortex PBT Doubleshots
Software Windows 10 64bit
Benchmark Scores http://www.3dmark.com/fs/12108888
oh no hehe.. I wont be limiting it to 4, since it can be any amount..
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,051 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
ORDER BY Create GROUP BY Suppl
 
Joined
Jan 2, 2008
Messages
3,296 (0.55/day)
System Name Thakk
Processor i7 6700k @ 4.5Ghz
Motherboard Gigabyte G1 Z170N ITX
Cooling H55 AIO
Memory 32GB DDR4 3100 c16
Video Card(s) Zotac RTX3080 Trinity
Storage Corsair Force GT 120GB SSD / Intel 250GB SSD / Samsung Pro 512 SSD / 3TB Seagate SV32
Display(s) Acer Predator X34 100hz IPS Gsync / HTC Vive
Case QBX
Audio Device(s) Realtek ALC1150 > Creative Gigaworks T40 > AKG Q701
Power Supply Corsair SF600
Mouse Logitech G900
Keyboard Ducky Shine TKL MX Blue + Vortex PBT Doubleshots
Software Windows 10 64bit
Benchmark Scores http://www.3dmark.com/fs/12108888
yep. that would certainly organize it out.. but I just want to remove the extras and leave the top most ones..

 
Joined
Sep 15, 2004
Messages
1,583 (0.22/day)
Location
Poland,Slask
System Name HAL
Processor Core i5 2500K
Motherboard Asus P8P67 Pro Rev3.1
Cooling stock
Memory 2x4GB Kingston 1600Mhz Blu
Video Card(s) Asus 560Ti DirectCuII TOP
Storage Kingston 120 3K SSD,WD Black WD1502FAEX
Display(s) LG 1440x900
Case Chieftec Mesh Midi
Audio Device(s) onboard
Power Supply Corsair TX750V2
Software w8
What about HAVING MAX() ?
I mean first selecting MAX and then joining to that. I think its possible somehow with HAVING or maybe the ranking functions but I always go the lame way :

SELECT * FROM A JOIN (SELECT ID,MAX(Create) FROM A GROUP BY ID) B ON A.ID=B.ID
 
Last edited:
Joined
Oct 10, 2008
Messages
3,471 (0.61/day)
System Name Acer Aspire V3-771G-53218G75Maii
Processor Core i5 3210M (2,5-3,1Ghz)
Memory 8GB DDR3 SODIMM
Video Card(s) Geforce GT650M
Storage Samsung 830 256GB - 750GB Toshiba drive
Software Windows 7 x64 Home Premium (non-acer-bloatware)
SELECT * FROM bla
WHERE NOT EXISTS (SELECT * from bla bla2 where bla2.suppl = bla.suppl and bla2.date > bla.date)

EDIT: I know it can be done more efficiently, but this was a quickie.
 
Joined
Dec 1, 2007
Messages
528 (0.09/day)
Location
Karachi, Pakistan
System Name mAkS
Processor Intel Core 2 Duo E0 E8400 @3.0Ghz (Acheived 4.4Ghz On Stock Cooling)
Motherboard Asus P5K-V (Dead :[ )
Cooling CPU + Front + Rear + Side
Memory XMS2 DHX TWIN2X2048-6400C5DHX/800 BUS
Video Card(s) Inno3D 9600 GT Overclocked
Storage Seagate Sata II 250 GB ++ 500 GB
Display(s) Hp 2009f 20-inch Wide-screen
Case Legend
Audio Device(s) Build-In 8 CHannel (Dell 5.1")
Power Supply CoolerMaster 460W eXtreme Power Plus
Software Many
Benchmark Scores E8400 hardware rank 94th on hwbot in wPrime :D
select top 4 * from table order by creation desc

I suppose you are using ms access, this query will sort the result by (latest at the top) and then give you the four results from the top.
 
Joined
Oct 10, 2008
Messages
3,471 (0.61/day)
System Name Acer Aspire V3-771G-53218G75Maii
Processor Core i5 3210M (2,5-3,1Ghz)
Memory 8GB DDR3 SODIMM
Video Card(s) Geforce GT650M
Storage Samsung 830 256GB - 750GB Toshiba drive
Software Windows 7 x64 Home Premium (non-acer-bloatware)
select top 4 * from table order by creation desc

I suppose you are using ms access, this query will sort the result by (latest at the top) and then give you the four results from the top.

yeah, but if the last 4 results are type '13' then you will not have the top result for each type ;)
 
Joined
Jan 2, 2008
Messages
3,296 (0.55/day)
System Name Thakk
Processor i7 6700k @ 4.5Ghz
Motherboard Gigabyte G1 Z170N ITX
Cooling H55 AIO
Memory 32GB DDR4 3100 c16
Video Card(s) Zotac RTX3080 Trinity
Storage Corsair Force GT 120GB SSD / Intel 250GB SSD / Samsung Pro 512 SSD / 3TB Seagate SV32
Display(s) Acer Predator X34 100hz IPS Gsync / HTC Vive
Case QBX
Audio Device(s) Realtek ALC1150 > Creative Gigaworks T40 > AKG Q701
Power Supply Corsair SF600
Mouse Logitech G900
Keyboard Ducky Shine TKL MX Blue + Vortex PBT Doubleshots
Software Windows 10 64bit
Benchmark Scores http://www.3dmark.com/fs/12108888
What about HAVING MAX() ?
I mean first selecting MAX and then joining to that. I think its possible somehow with HAVING or maybe the ranking functions but I always go the lame way :

SELECT * FROM A JOIN (SELECT ID,MAX(Create) FROM A GROUP BY ID) B ON A.ID=B.ID
Holy crap that worked! haha. Thanks for the pro tip

went something like this:

SELECT * FROM A JOIN (SELECT ID,MAX(Create) AS Create FROM A GROUP BY ID my where clauses) B ON A.ID=B.ID my where clauses)
 
Last edited:
Top