Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

 

ich habe einen recht komplizierten fachlichen Sachverhalt, den ich jetzt hier versuche, aufs Forum runterzubrechen.

 

Ich habe folgende Tabelle

Artikel-Nr  1 				Artikel-Nr  2
001							4711
001							4712
001							4713
002							0815
002							0816

 

Über einen Geschäftsfall habe ich z.B. nur die 4712 an der Hand.

Was ich hierzu noch bräuchte, wäre die passende Artikelnummer 1 (001), sowie die dazu verknüpften Artikelnummern 2 (4711, 4713).

 

Dies ist nur ein Fall von vielen, den ich zusätzlich in ein UNION reinpacken müsste. 

Bekomme ich das über ein Subselect gelöst? Bin leider nur recht einfach immer in SQL unterwegs gewesen mit Subselects kenne ich mich jetzt nur vom Hörensagen aus. Hier im SQL Tool bekomme ich es nicht gebacken.

Oder ist das der komplett falsche Ansatz?

Programmiert bekäme ich das in mehreren Schritten aber als ein SELECT-Statement? Keine Ahnung...

 

Hat wer Rat?

 

Gruß

Ganymede

Spiel mal ein wenig mit

SELECT * FROM Article 
    WHERE "Artikel-Nr 1" IN (SELECT "Artikel-Nr 1" FROM Article 
                            WHERE "Artikel-Nr 2" = 4712)

Bei großen Tabellen kann es teuer werden. Alternativ bau dir eine Stored Procedure.
 

  • Autor

Hallo Goose,

 

ja so etwas habe ich auch gebaut. Danke Dir!

Dann bin ich ja nicht ganz auf dem Holzweg damit.

 

Ich weiß, dass das teuer ist. Die Anforderung ist aber alles in ein Select. Und wie gesagt, das ist eines von vielen. Das WIRD langsam.

SELECT
    articlesWanted.*
FROM
    articles AS article2
INNER JOIN articles AS article1 
	ON article2.articlenr2 = article1.articlenr2
INNER JOIN articles AS articlesWanted 
	ON article1.articlenr1 = articlesWanted.articlenr1
WHERE
    article2.articlenr2 = 4712

Sollte von der Performance her jetzt nichts heftiges sein, eventuell halt Index setzen.

Bearbeitet von PVoss

  • 1 Monat später...
Am 26.9.2016 um 11:00 schrieb PVoss:

SELECT
    articlesWanted.*
FROM
    articles AS article2
INNER JOIN articles AS article1 
	ON article2.articlenr2 = article1.articlenr2
INNER JOIN articles AS articlesWanted 
	ON article1.articlenr1 = articlesWanted.articlenr1
WHERE
    article2.articlenr2 = 4712

Sollte von der Performance her jetzt nichts heftiges sein, eventuell halt Index setzen.

Brrr, kann man so nicht stehen lassen.

Hier ist ein simpler JOIN auf die selbe Tabelle gefragt.

SELECT
    articlesWanted.*
FROM
    articles AS article
INNER JOIN articles AS articlesWanted 
	ON article.articlenr1 = articlesWanted.articlenr1
WHERE
    article.articlenr2 = 4712

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.