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,

ich komm leider grad netmal druaf nach was ich suchen muss.

also mein problem:

ich habe zwei tabellen.

Tabelle A

mit x Feldern. wichtigstes: Barcode

Tabelle B ebenfalls mit Barcode

Nun stehen in Tabelle A alle Barcodes.

in Tabelle B stehen aber nicht alle drin.

Wie funktioniert es nun das ich die die in Tabelle A stehen in Tabelle B mit hinzufüge. Das zweite Feld in Tabelle B muss dabei NULL sein.

Irgendwie mit INSERT INTO nur args, irgendwie hat mich mein Hirn schon ins Wochenende verabschiedet.

Danke für jeden Tip.

Gruß

Enno

insert into <tabelle_b> (barcode,null_spalte) select barcode,null from tabelle_a;

-j

  • Autor

aehm und was passiert wenn der barcode aus tabelle a schon in tabelle b enthalten ist, der darf ja nur 1mal vorkommen. bzw. wenn er schon in tabelle b vorhanden ist darf ich den nicht nochmal einfügen.

oh sorry hat ich oben nicht geschrieben.

Wenn du 'Barcode' als Primärschlüssel hast wirds n Fehler geben oder übersprungen, jenachdem, wie sich die DB verhalten soll.

Wenn in Tabelle_b keine weiteren wichtigen Daten sind, lösch allen Inhalt aus B und für das Statement von Jasper aus.

Ansonsten müsste man checken, ob der aktuelle Barcode bereits in B vorhanden ist.

aehm und was passiert wenn der barcode aus tabelle a schon in tabelle b enthalten ist, der darf ja nur 1mal vorkommen. bzw. wenn er schon in tabelle b vorhanden ist darf ich den nicht nochmal einfügen.

insert into b (id) select id from a where id not in (select id from B);

-j

Dein Stichwort ist

merge

gruss


>>-MERGE INTO--+-table-name-------+----------------------------->
2 +-view-name--------+
2 '-4 (2 --4 fullselect2 --4 )2 -'
2
2 >--+------------------------+--USING--table-reference----------->
2 '-4 | correlation-clause |2 -'
2
2 >--ON--search-condition----------------------------------------->
2
2 .--------------------------------------------------------------------.
2 V |
2 >----WHEN--| matching-condition |--THEN--+-| modification-operation |-+-+-->
2 '-signal-statement-----------'
2
2 .-ELSE IGNORE-.
2 >--+-------------+---------------------------------------------><
2
2 correlation-clause:
2
2 .-4 AS2 -.
2 |--+----+--4 correlation-name2 --+-----------------------+----------|
2 | .-,-----------. |
2 | V | |
2 '-4 (2 ----4 column-name2 -+--4 )2 -'
2
2 matching-condition:
2
2 |--+-----+--MATCHED--+-----------------------+------------------|
2 '-NOT-' '-AND--search-condition-'
2
2 modification-operation:
2
2 |--+-UPDATE SET--| assignment-clause |-+------------------------|
2 +-DELETE----------------------------+
2 '-| insert-operation |--------------'
2
2 assignment-clause:
2
2 .-,--------------------------------------------------------.
2 V |
2 |----+-column-name-- = --+-expression-+---------------------+-+--|
2 | +-DEFAULT----+ |
2 | '-NULL-------' |
2 | .-,-----------. .-,--------------. |
2 | V | V | |
2 '-(----column-name-+--)-- = --(----+-expression-+-+--)-'
2 +-DEFAULT----+
2 '-NULL-------'
2
2 insert-operation:
2
2 |--INSERT--+-----------------------+---------------------------->
2 | .-,-----------. |
2 | V | |
2 '-(----column-name-+--)-'
2
2 >--VALUES--+-+-expression-+-----------+-------------------------|
2 | +-DEFAULT----+ |
2 | '-NULL-------' |
2 | .-,--------------. |
2 | V | |
2 '-(----+-expression-+-+--)-'
2 +-DEFAULT----+
2 '-NULL-------'

[/PHP]

Hab ungefähr das gleiche Problem

Hab zwei Tabellen in denen sich der gleiche Inhalt befindet. Fast zumindest. Wie kann ich es schaffen das alles aus der einen Tabelle in die andere übernommen wird, bis auf das was schon vorhanden ist. Das mit dem not in geht doch nur bei einem Primary Key, oder?

Bei mir wären es insgesamt drei.

Evtl hilft mir die Lösung von zirri, aber ich versteh net so ganz wie da was funktioniert ;)

aber doch immer nur mit einem primary key, oder?

weil wenn ich sage

insert into abc ( a,b,c )

where a,b,c not in ( select a,b,c from x )

Dann geht das nicht.

Ach.. das ganze sind zusammengesetzte primary keys

weil wenn ich sage

insert into abc ( a,b,c )

where a,b,c not in ( select a,b,c from x )


Insert Into y(a,b,c) Select a,b,c from x where a not in (select a from y)

and b not in (select b from y)

and c not in (select c from y);

Ansonsten poste doch mal die Fehlermeldung. Das hilft bestimmt weiter als die Aussage das es nicht geht ;)

Ok so funktioniert das ja theoretisch.

Aber irgendwie begreif ich des im moment net ganz.. könnte auch an der Uhrzeit liegen ( 14Stunden + x auf Arbeit ist glaub ich net so gut )

Also bei mir ist ein Datensatz eindeutig wenn alle drei werte den wert z.b. 1,2 und 3 haben. Es kann aber auch noch 1,2,4 vorkommen usw.

Mit deinem Code würde ich doch theoretisch nix bekommen, da eine zahl mit großer wahrscheinlichkeit immer vorkommt!?

Also bei mir ist ein Datensatz eindeutig wenn alle drei werte den wert z.b. 1,2 und 3 haben. Es kann aber auch noch 1,2,4 vorkommen usw.

Mit deinem Code würde ich doch theoretisch nix bekommen, da eine zahl mit großer wahrscheinlichkeit immer vorkommt!?

Da hast du vollkommen recht. So spontan fällt mir für dieses Problem allerdings auch keine Lösung ein

Sorry :(

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.