Hello
Please help
I can't do it by myself.
I have three tables:
Towary, Kontrahenci and TwrIlosci
The TWrIlosci table is linked to the first via id and contains entries with different dates.
I'd like to display only the entries for the last date
I have this query but it shows all entries
Sorry for that I forgot to paste data
<pre>
Table Towary
twr_kod twr_nazwa twr_numerkat twr_koddostawcy twr_iloscmin
MECCZ-TK7598/A PAL 0.0000
MECCZ-TK7605 NAPY 0.0000
MECCZ-TK7722 KOLO 1 0.0000
MECCZ-TK7723 KOLO 2 0.0000
MECCZ-TK7741 ZEST 0.0000
Table Kontrahenci
knt_kod knt_kntid
!NIEOKREŚLONY! 1
00000 1853
10-05-1039 2239
10-05-1052 2253
10-05-1090 2309
Table TwrIlosci
twi_ilosc twi_rezerwacje twi_zamowienia twi_data TwI_TwrId
0.0000 0.0000 0.0000 2011-05-05 00:00:00.000 57
1.0000 0.0000 0.0000 2011-04-30 00:00:00.000 57
0.0000 0.0000 0.0000 2011-05-05 00:00:00.000 57
1.0000 0.0000 0.0000 2011-04-30 00:00:00.000 57
0.0000 0.0000 0.0000 2017-06-20 00:00:00.000 132
An example answer to my query
twr_kod twr_nazwa twr_numerkat twr_koddostawcy knt_kod twr_iloscmin twi_ilosc twi_rezerwacje twi_zamowienia twi_data
MSP321528-0-00 ZTYLNIE 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSP321528-0-00 ZTYLNIE 6-10-11-MSP 0.0000 1.0000 0.0000 0.0000 2011-04-30 00:00:00.000
MSP321528-0-00 ZTYLNIE 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSP321528-0-00 ZTYLNIE 6-10-11-MSP 0.0000 1.0000 0.0000 0.0000 2011-04-30 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2017-06-20 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2012-05-22 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 10.0000 0.0000 0.0000 2012-05-17 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2017-06-20 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2012-05-22 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 10.0000 0.0000 0.0000 2012-05-17 00:00:00.000
MSPRM101572-012 CHWYTACZ C 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2015-05-07 00:00:00.000
MSPRM101572-012 CHWYTACZ C 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2015-05-07 00:00:00.000
MSPRM202092-0-1 CHWYTACZ G 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSPRM202092-0-1 CHWYTACZ G 6-10-11-MSP 0.0000 1.0000 0.0000 0.0000 2011-04-30 00:00:00.000
MSPRM202092-0-1 CHWYTACZ G 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSPRM202092-0-1 CHWYTACZ G 6-10-11-MSP 0.0000 1.0000 0.0000 0.0000 2011-04-30 00:00:00.000
MSPRM202095-013 N DOLNY 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2016-10-17 00:00:00.000
MSPRM202095-013 N DOLNY 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2015-10-19 00:00:00.000
MSPRM202095-013 N DOLNY 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2016-10-17 00:00:00.000
MSPRM202095-013 N DOLNY 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2015-10-19 00:00:00.000
I would like to have only:
twr_kod twr_nazwa twr_numerkat twr_koddostawcy knt_kod twr_iloscmin twi_ilosc twi_rezerwacje twi_zamowienia twi_data
MSP321528-0-00 ZTYLNIE 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSPRM100458-010 SRUBA SCREW RM100458-0-10 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2017-06-20 00:00:00.000
MSPRM101572-012 CHWYTACZ C 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2015-05-07 00:00:00.000
MSPRM202092-0-1 CHWYTACZ G 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2011-05-05 00:00:00.000
MSPRM202095-013 N DOLNY 6-10-11-MSP 0.0000 0.0000 0.0000 0.0000 2016-10-17 00:00:00.000
What I have tried:
SELECT
twr_kod, twr_nazwa, twr_numerkat, twr_koddostawcy, knt_kod, twr_iloscmin, twi_ilosc, twi_rezerwacje, twi_zamowienia, twi_data
FROM ((XL.Towary
INNER JOIN XL.Kontrahenci ON XL.Towary.twr_kntid = XL.Kontrahenci.knt_kntid)
INNER JOIN
XL.TwrIlosci ON XL.TOWARY.Twr_TwrId = XL.TwrIlosci.TwI_TwrId)