Ankündigung

Einklappen
Keine Ankündigung bisher.

Abfrage aus zwei Tabellen - Neuster Eintrag aus zweiter

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Abfrage aus zwei Tabellen - Neuster Eintrag aus zweiter

    Hallo allerseits

    Ich bin mir sicher das Google da was hergeben müsste, aber anscheinend suche ich einfach nach dem falschen.
    Hoffe Ihr könnt mir helfen!

    Ich habe aktuell folgende Abfrage beieinander:
    Code:
    SELECT * FROM V1__Index AS I LEFT JOIN V1__HeadData AS H ON I.IhsImpId = H.IhsImpId ORDER BY H.Date_InvoiceIssue
    In meinen Testdaten gibt es in der HeadData Tabelle zu jeder IhsImpId zwei Einträge.
    Mit der oben gezeigten Abfrage erhalte ich nun also 10 Resultate obwohl meine V1__Index Tabelle nur 5 Einträge hat.

    Frage:
    Wie bekomme ich es hin das mir die 5 Einträge aus der V1__Index Tabelle angezeigt werden, verknüpft mit der jeweils neusten Zeile aus V1__HeadData (Zeile ReadDateTime gibt an wann die Zeile erstellt wurde)


    Danke schon mal für eure Hilfe

    petrei86

  • #2
    https://dev.mysql.com/doc/refman/8.0...group-row.html

    Kommentar


    • #3
      Sorry, ich verstehe es nicht!
      In deinem Beispiel geht es um um die doppelte Abfrage der selben Tabelle. Aber ich habe ja in meiner V1__Index kein ReadDateTime!?

      Bei mir soll aus der Tabelle V1__HeadData die Zeile mit dem höchsten ReadDateTime verwendet werden ohne Refernz des ReadDateTime in der V1__Index!?!

      Hoffe du kannst mir auf die Sprünge helfen...

      Kommentar


      • #4
        Joine eine Subquery drauf, die nur die MAX-Datensätze von Head-Data beinhaltet.
        Wenn du einen SQL Dump mit Testdaten bereitstellst kann man auch besser helfen.
        sorry, shift-taste kaputt

        Kommentar


        • #5
          Ging etwas länger aber, habs jetzt raus:

          Code:
          SELECT MAX(H.ReadDateTime ) AS test, I.IhsImpId, H.Id FROM V1__Index I LEFT JOIN V1__HeadData H ON I.IhsImpId = H.IhsImpId GROUP BY I.IhsImpId"
          MAX(...) stellt dabei sicher das aus der Tabelle H der Eintrag mit dem höchsten ReadDateTime genommen wird.
          GROUP BY gruppiert das ganze nach der IhsImpId

          Kommentar


          • #6
            Das H.Id ist problematisch, denn jedes Feld im SELECT muss entweder gruppiert werden oder mit einer Aggregatfunktion versehen sein.
            MySQL erkennt dies nicht als Fehler und liefert ein "zufälliges" Ergebnis.
            sorry, shift-taste kaputt

            Kommentar


            • #7
              Zitat von Meister1900 Beitrag anzeigen
              Das H.Id ist problematisch, denn jedes Feld im SELECT muss entweder gruppiert werden oder mit einer Aggregatfunktion versehen sein.
              MySQL erkennt dies nicht als Fehler und liefert ein "zufälliges" Ergebnis.
              Das musste ich leider zwischenzeitlich auch feststellen. Was kann ich den nun tun damit alle Felder aus der selben Zeile von V1__HeadData kommen?

              Kommentar


              • #8
                Zitat von Meister1900 Beitrag anzeigen
                ...
                Wenn du einen SQL Dump mit Testdaten bereitstellst kann man auch besser helfen.
                Das denke ich auch.

                Kommentar


                • #9
                  Danke euch für eure Hilfe!

                  Anbei der Link mit einem Dump (ReadDateTime ist hier nun TS_Extraction)

                  Ziel: Eine Liste aller Einträge aus V1__Index mit jeweils dem neusten (TS_Extraction) aus V1__HeadData integriert - Verknüpft über IhsImpId

                  Kommentar


                  • #10
                    Der Link ist nicht brauchbar, wer will sich das ganze Internet runterladen?
                    Du kannst bei solchen Problem ganz normal den Code eines Select Statements, Create Table, Insert Statements hier posten, dann wissen alle Bescheid und können konkretere Hilfestellung geben.
                    In Deinem Fall vielleicht aber gar nicht nötig, hier steht schon, was zu tun ist.
                    Zitat von Meister1900 Beitrag anzeigen
                    Das H.Id ist problematisch, denn jedes Feld im SELECT muss entweder gruppiert werden oder mit einer Aggregatfunktion versehen sein.
                    Ein Group by ist unvollständig, wenn diese Regel nicht erfüllt ist. Das ist bei Dir der Fall. H.ID fehlt in der Group by clause.
                    Ein Feld, das Du in der Select Clause ausgibst, muss entweder gruppiert werden oder aggregiert, z.B. mit Max.

                    Der unterstrichene, kursive Teil wird auch Faustregel für Group by genannt. Faustregel, weil er nicht alle Fälle beschreibt, sondern nur 99%.
                    Diese einfache Regel sollte man immer anwenden, wenn man ein Group by schreibt.

                    Man kann natürlich auch die Bedeutung nachvollziehen, dann muss man sich nicht mehr diese komische Regel merken und erkennt am ehesten auch die Fälle, wo es anders läuft (selten).

                    So sollte es besser funktionieren:
                    Code:
                    SELECT MAX(H.ReadDateTime) AS test, I.IhsImpId, H.Id
                    FROM V1__Index I
                    LEFT JOIN V1__HeadData H
                    ON I.IhsImpId = H.IhsImpId
                    GROUP BY I.IhsImpId, H.Id

                    Kommentar


                    • #11
                      Zitat von Perry Staltic Beitrag anzeigen
                      So sollte es besser funktionieren:
                      Code:
                      SELECT MAX(H.ReadDateTime) AS test, I.IhsImpId, H.Id
                      FROM V1__Index I
                      LEFT JOIN V1__HeadData H
                      ON I.IhsImpId = H.IhsImpId
                      GROUP BY I.IhsImpId, H.Id
                      Das habe ich schon probiert (zur Sicherheit soeben nochmal), aber so bekomme ich jede IhsImpId zweimal.

                      Hier mein Dump

                      Code:
                      -- phpMyAdmin SQL Dump
                      -- version 4.8.3
                      -- https://www.phpmyadmin.net/
                      --
                      -- Host: localhost:3306
                      -- Erstellungszeit: 18. Aug 2019 um 21:37
                      -- Server-Version: 5.7.26-log-cll-lve
                      -- PHP-Version: 7.2.7
                      
                      SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
                      SET AUTOCOMMIT = 0;
                      START TRANSACTION;
                      SET time_zone = "+00:00";
                      
                      
                      /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
                      /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
                      /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
                      /*!40101 SET NAMES utf8mb4 */;
                      
                      --
                      -- Datenbank: `ihs_Master`
                      --
                      
                      -- --------------------------------------------------------
                      
                      --
                      -- Tabellenstruktur für Tabelle `V1__HeadData`
                      --
                      
                      CREATE TABLE `V1__HeadData` (
                        `Id` int(8) NOT NULL,
                        `IhsImpId` int(8) NOT NULL,
                        `InvoiceNumber` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
                        `TS_Extraction` datetime NOT NULL,
                        `ExtractionType` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '#',
                        `SenderVat` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
                        `SenderPsAdrId` int(10) NOT NULL,
                        `Recipient` enum('K','B','#') COLLATE utf8_unicode_ci NOT NULL DEFAULT '#',
                        `AmountTotal` decimal(7,2) NOT NULL,
                        `Date_InvoiceIssue` date NOT NULL,
                        `Date_InvoiceExpiry` date NOT NULL,
                        `FullTextContent` mediumtext COLLATE utf8_unicode_ci NOT NULL
                      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
                      
                      --
                      -- Daten für Tabelle `V1__HeadData`
                      --
                      
                      INSERT INTO `V1__HeadData` (`Id`, `IhsImpId`, `InvoiceNumber`, `TS_Extraction`, `ExtractionType`, `SenderVat`, `SenderPsAdrId`, `Recipient`, `AmountTotal`, `Date_InvoiceIssue`, `Date_InvoiceExpiry`, `FullTextContent`) VALUES
                      (1, 1, '90704128', '2019-08-18 12:00:05', 'basic-extraction', '', 147044, '#', '0.00', '2018-08-24', '0000-00-00', ''),
                      (2, 2, '90704128', '2019-08-18 12:00:06', 'basic-extraction', '', 147046, '#', '0.00', '2018-08-24', '0000-00-00', ''),
                      (3, 3, '607614', '2019-08-18 12:00:07', 'basic-extraction', '', 147045, '#', '0.00', '2019-07-16', '0000-00-00', ''),
                      (4, 4, '70289405', '2019-08-18 12:00:07', 'basic-extraction', '', 147084, '#', '0.00', '2019-08-04', '0000-00-00', ''),
                      (5, 5, '25,066,802', '2019-08-18 12:00:08', 'basic-extraction', '', 147047, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (6, 6, '1-00001-70165-2', '2019-08-18 12:00:09', 'basic-extraction', '', 147048, '#', '0.00', '2019-07-14', '0000-00-00', ''),
                      (7, 7, '238820', '2019-08-18 12:00:09', 'basic-extraction', '', 147052, '#', '0.00', '2019-07-22', '0000-00-00', ''),
                      (8, 8, 'GW2019/0019204', '2019-08-18 12:00:10', 'basic-extraction', '', 147049, '#', '0.00', '2019-05-31', '0000-00-00', ''),
                      (9, 9, '9535205516', '2019-08-18 12:00:10', 'basic-extraction', '', 147085, '#', '0.00', '2019-08-05', '0000-00-00', ''),
                      (10, 10, '06561-0925007', '2019-08-18 12:00:11', 'basic-extraction', '', 147087, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (11, 11, '2019-51441', '2019-08-18 12:00:11', 'basic-extraction', '', 147053, '#', '0.00', '2019-07-16', '0000-00-00', ''),
                      (12, 12, '231800', '2019-08-18 12:00:12', 'basic-extraction', '', 147054, '#', '0.00', '2019-06-01', '0000-00-00', ''),
                      (13, 13, 'RE14191437', '2019-08-18 12:00:12', 'basic-extraction', '', 147069, '#', '0.00', '2019-06-18', '0000-00-00', ''),
                      (14, 14, '', '2019-08-18 12:00:13', 'basic-extraction', '', 147070, '#', '0.00', '0000-00-00', '0000-00-00', ''),
                      (15, 15, '1047030', '2019-08-18 12:00:13', 'basic-extraction', '', 147079, '#', '0.00', '2019-07-17', '0000-00-00', ''),
                      (16, 16, '1900005152', '2019-08-18 12:00:14', 'basic-extraction', '', 147078, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (17, 17, '92273', '2019-08-18 12:00:15', 'basic-extraction', '', 147080, '#', '0.00', '2019-08-16', '0000-00-00', ''),
                      (18, 18, '161746', '2019-08-18 12:00:15', 'basic-extraction', '', 147275, '#', '0.00', '2019-08-14', '0000-00-00', ''),
                      (19, 19, '35402-1908', '2019-08-18 12:00:16', 'basic-extraction', '', 147276, '#', '0.00', '2019-08-15', '0000-00-00', ''),
                      (20, 1, '90704128', '2019-08-18 11:50:05', 'basic-extraction', '', 147044, '#', '0.00', '2018-08-24', '0000-00-00', ''),
                      (21, 2, '90704128', '2019-08-18 12:50:05', 'basic-extraction', '', 147046, '#', '0.00', '2018-08-24', '0000-00-00', ''),
                      (22, 3, '607614', '2019-08-18 12:50:06', 'basic-extraction', '', 147045, '#', '0.00', '2019-07-16', '0000-00-00', ''),
                      (23, 4, '70289405', '2019-08-18 12:50:06', 'basic-extraction', '', 147084, '#', '0.00', '2019-08-04', '0000-00-00', ''),
                      (24, 5, '25,066,802', '2019-08-18 12:50:07', 'basic-extraction', '', 147047, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (25, 6, '1-00001-70165-2', '2019-08-18 12:50:07', 'basic-extraction', '', 147048, '#', '0.00', '2019-07-14', '0000-00-00', ''),
                      (26, 7, '238820', '2019-08-18 12:50:08', 'basic-extraction', '', 147052, '#', '0.00', '2019-07-22', '0000-00-00', ''),
                      (27, 8, 'GW2019/0019204', '2019-08-18 12:50:08', 'basic-extraction', '', 147049, '#', '0.00', '2019-05-31', '0000-00-00', ''),
                      (28, 9, '9535205516', '2019-08-18 12:50:09', 'basic-extraction', '', 147085, '#', '0.00', '2019-08-05', '0000-00-00', ''),
                      (29, 10, '06561-0925007', '2019-08-18 12:50:09', 'basic-extraction', '', 147087, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (30, 11, '2019-51441', '2019-08-18 12:50:10', 'basic-extraction', '', 147053, '#', '0.00', '2019-07-16', '0000-00-00', ''),
                      (31, 12, '231800', '2019-08-18 12:50:10', 'basic-extraction', '', 147054, '#', '0.00', '2019-06-01', '0000-00-00', ''),
                      (32, 13, 'RE14191437', '2019-08-18 12:50:10', 'basic-extraction', '', 147069, '#', '0.00', '2019-06-18', '0000-00-00', ''),
                      (33, 14, '', '2019-08-18 12:50:11', 'basic-extraction', '', 147070, '#', '0.00', '0000-00-00', '0000-00-00', ''),
                      (34, 15, '1047030', '2019-08-18 12:50:11', 'basic-extraction', '', 147079, '#', '0.00', '2019-07-17', '0000-00-00', ''),
                      (35, 16, '1900005152', '2019-08-18 12:50:12', 'basic-extraction', '', 147078, '#', '0.00', '2019-07-31', '0000-00-00', ''),
                      (36, 17, '92273', '2019-08-18 12:50:12', 'basic-extraction', '', 147080, '#', '0.00', '2019-08-16', '0000-00-00', ''),
                      (37, 18, '161746', '2019-08-18 12:50:13', 'basic-extraction', '', 147275, '#', '0.00', '2019-08-14', '0000-00-00', ''),
                      (38, 19, '35402-1908', '2019-08-18 12:50:13', 'basic-extraction', '', 147276, '#', '0.00', '2019-08-15', '0000-00-00', ''),
                      (39, 1, '90704128', '2019-08-18 19:04:02', 'basic-extraction', '', 147044, '#', '653.00', '2018-08-24', '0000-00-00', ''),
                      (40, 2, '90704128', '2019-08-18 19:04:02', 'basic-extraction', '', 147046, '#', '653.00', '2018-08-24', '0000-00-00', ''),
                      (41, 3, '607614', '2019-08-18 19:04:03', 'basic-extraction', '', 147045, '#', '144.30', '2019-07-16', '0000-00-00', ''),
                      (42, 4, '70289405', '2019-08-18 19:04:03', 'basic-extraction', '', 147084, '#', '893.35', '2019-08-04', '0000-00-00', ''),
                      (43, 5, '25,066,802', '2019-08-18 19:04:03', 'basic-extraction', '', 147047, '#', '556.40', '2019-07-31', '0000-00-00', ''),
                      (44, 6, '1-00001-70165-2', '2019-08-18 19:04:04', 'basic-extraction', '', 147048, '#', '394.20', '2019-07-14', '0000-00-00', ''),
                      (45, 7, '238820', '2019-08-18 19:04:04', 'basic-extraction', '', 147052, '#', '1146.00', '2019-07-22', '0000-00-00', ''),
                      (46, 8, 'GW2019/0019204', '2019-08-18 19:04:04', 'basic-extraction', '', 147049, '#', '121.18', '2019-05-31', '0000-00-00', ''),
                      (47, 9, '9535205516', '2019-08-18 19:04:05', 'basic-extraction', '', 147085, '#', '80.55', '2019-08-05', '0000-00-00', ''),
                      (48, 10, '06561-0925007', '2019-08-18 19:04:05', 'basic-extraction', '', 147087, '#', '1217.45', '2019-07-31', '0000-00-00', ''),
                      (49, 11, '2019-51441', '2019-08-18 19:04:05', 'basic-extraction', '', 147053, '#', '607.45', '2019-07-16', '0000-00-00', ''),
                      (50, 12, '231800', '2019-08-18 19:04:06', 'basic-extraction', '', 147054, '#', '524.29', '2019-06-01', '0000-00-00', ''),
                      (51, 13, 'RE14191437', '2019-08-18 19:04:06', 'basic-extraction', '', 147069, '#', '240.00', '2019-06-18', '0000-00-00', ''),
                      (52, 14, '', '2019-08-18 19:04:06', 'basic-extraction', '', 147070, '#', '1500.00', '0000-00-00', '0000-00-00', ''),
                      (53, 15, '1047030', '2019-08-18 19:04:07', 'basic-extraction', '', 147079, '#', '775.45', '2019-07-17', '0000-00-00', ''),
                      (54, 16, '1900005152', '2019-08-18 19:04:07', 'basic-extraction', '', 147078, '#', '21540.00', '2019-07-31', '0000-00-00', ''),
                      (55, 17, '92273', '2019-08-18 19:04:08', 'basic-extraction', '', 147080, '#', '-26700.00', '2019-08-16', '0000-00-00', ''),
                      (56, 18, '161746', '2019-08-18 19:04:08', 'basic-extraction', '', 147275, '#', '344.60', '2019-08-14', '0000-00-00', ''),
                      (57, 19, '35402-1908', '2019-08-18 19:04:08', 'basic-extraction', '', 147276, '#', '69.85', '2019-08-15', '0000-00-00', '');
                      
                      -- --------------------------------------------------------
                      
                      --
                      -- Tabellenstruktur für Tabelle `V1__Index`
                      --
                      
                      CREATE TABLE `V1__Index` (
                        `IhsImpId` int(8) NOT NULL,
                        `PsImpId` int(10) NOT NULL,
                        `RawFileName` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
                        `ImpType` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
                        `ExtractionType_State` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
                        `ExtractionType_Target` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
                        `ValidationType` enum('GENERAL','TRADE','MANAGEMENT') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'MANAGEMENT',
                        `TS_ScanOrMailIn` datetime NOT NULL,
                        `TS_Transfer` datetime NOT NULL,
                        `Id` int(2) NOT NULL
                      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
                      
                      --
                      -- Daten für Tabelle `V1__Index`
                      --
                      
                      INSERT INTO `V1__Index` (`IhsImpId`, `PsImpId`, `RawFileName`, `ImpType`, `ExtractionType_State`, `ExtractionType_Target`, `ValidationType`, `TS_ScanOrMailIn`, `TS_Transfer`, `Id`) VALUES
                      (1, 181186, '20190813-101122_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-13 10:11:22', '2019-08-16 15:34:02', 0),
                      (2, 181187, '20190816-153454_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:34:54', '2019-08-16 15:35:01', 0),
                      (3, 181188, '20190813-102222_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-13 10:22:22', '2019-08-16 15:35:03', 0),
                      (4, 181189, '20190813-103322_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-13 10:33:22', '2019-08-16 15:35:05', 0),
                      (5, 181190, '20190813-104422_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-13 10:44:22', '2019-08-16 15:35:05', 0),
                      (6, 181191, '20190816-153546_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:35:46', '2019-08-16 15:36:02', 0),
                      (7, 181192, '20190816-153709_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:37:09', '2019-08-16 15:38:01', 0),
                      (8, 181193, '20190816-153731_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:37:31', '2019-08-16 15:38:02', 0),
                      (9, 181194, '20190816-153742_MAILIN_INVOICE-MANAGEMENT_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:37:42', '2019-08-16 15:38:03', 0),
                      (10, 181197, '20190816-153810_MAILIN_INVOICE-TRADE_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:38:10', '2019-08-16 15:39:01', 0),
                      (11, 181198, '20190816-154123_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:41:23', '2019-08-16 15:42:01', 0),
                      (12, 181199, '20190816-154159_MAILIN_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 15:41:59', '2019-08-16 15:42:01', 0),
                      (13, 181216, '20190816-163531_MAILIN_INVOICE-MANAGEMENT_STATE-N.pdf', 'MailIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 16:35:31', '2019-08-16 16:36:02', 0),
                      (14, 181217, '20190816-164030_MAILIN_INVOICE-TRADE_STATE-N.pdf', 'MailIn', 'basic-extraction', 'full-extraction', 'TRADE', '2019-08-16 16:40:30', '2019-08-16 16:41:01', 0),
                      (15, 181225, '20190816-165645_DRU43_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'GENERAL', '2019-08-16 16:56:45', '2019-08-16 16:54:02', 0),
                      (16, 181226, '20190816-165736_DRU43_INVOICE-MANAGEMENT_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'MANAGEMENT', '2019-08-16 16:57:36', '2019-08-16 16:54:03', 0),
                      (17, 181227, '20190816-165834_DRU43_INVOICE-TRADE_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'TRADE', '2019-08-16 16:58:34', '2019-08-16 16:55:02', 0),
                      (18, 181469, '20190816-074113_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'GENERAL', '2019-08-16 07:41:13', '2019-08-17 15:15:03', 0),
                      (19, 181470, '20190816-074049_DRU20_INVOICE-GENERAL_STATE-N.pdf', 'FtpIn', 'basic-extraction', 'full-extraction', 'GENERAL', '2019-08-16 07:40:49', '2019-08-17 15:24:01', 0);
                      
                      --
                      -- Indizes der exportierten Tabellen
                      --
                      
                      --
                      -- Indizes für die Tabelle `V1__HeadData`
                      --
                      ALTER TABLE `V1__HeadData`
                        ADD PRIMARY KEY (`Id`);
                      
                      --
                      -- Indizes für die Tabelle `V1__Index`
                      --
                      ALTER TABLE `V1__Index`
                        ADD PRIMARY KEY (`IhsImpId`);
                      
                      --
                      -- AUTO_INCREMENT für exportierte Tabellen
                      --
                      
                      --
                      -- AUTO_INCREMENT für Tabelle `V1__HeadData`
                      --
                      ALTER TABLE `V1__HeadData`
                        MODIFY `Id` int(8) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=58;
                      
                      --
                      -- AUTO_INCREMENT für Tabelle `V1__Index`
                      --
                      ALTER TABLE `V1__Index`
                        MODIFY `IhsImpId` int(8) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20;
                      COMMIT;
                      
                      /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
                      /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
                      /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
                      Freue mich auf eure Hilfe

                      Kommentar


                      • #12
                        Wie gesagt mit einem Subquery

                        Code:
                        SELECT *
                        FROM V1__Index i
                        JOIN (
                            SELECT MAX(H.TS_Extraction) max_date, H.IhsImpId
                            FROM V1__HeadData H
                            GROUP BY H.IhsImpId) head_max on head_max.IhsImpId = i.IhsImpId
                        JOIN V1__HeadData HD on HD.IhsImpId = I.IhsImpId AND HD.TS_Extraction = head_max.max_date
                        sorry, shift-taste kaputt

                        Kommentar


                        • #13
                          Zitat von petrei86 Beitrag anzeigen

                          Das habe ich schon probiert , aber so bekomme ich jede IhsImpId zweimal.
                          --snip--

                          Freue mich auf eure Hilfe
                          Sorry, da hab ich nicht aufgepasst.
                          Die Erklärung zu Group By ist dennoch richtig und merkwürdig(!), auch wenn sie nicht Dein Problem löst.

                          Kommentar

                          Lädt...
                          X